From 8b9db66ddd0381706d22e4fabd731bf39103cad9 Mon Sep 17 00:00:00 2001 From: Serguey Zefiov Date: Mon, 10 Feb 2025 20:18:06 +0000 Subject: [PATCH] fix(MCOL-5889): Improper handle of DOUBLE result type with DECIMAL arguments Sometimes server assigns DOUBLE type for arithmetic operations over DECIMAL arguments. In this rare case width of result was incorrectly adjusted and it triggered an assertion. Now width of result gets adjusted only if result type is also DECIMAL. --- dbcon/mysql/ha_mcs_execplan.cpp | 3 ++- .../MCOL-5889-double-is-not-decimal.result | 25 +++++++++++++++++++ .../MCOL-5889-double-is-not-decimal.test | 24 ++++++++++++++++++ tests/scripts/fullmtr.sh | 6 +++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.result create mode 100644 mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.test diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 6ec3990ce..a597155e6 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -4025,7 +4025,8 @@ ReturnedColumn* buildArithmeticColumnBody(Item_func* item, gp_walk_info& gwi, bo int32_t leftColWidth = leftColType.colWidth; int32_t rightColWidth = rightColType.colWidth; - if (leftColWidth == datatypes::MAXDECIMALWIDTH || rightColWidth == datatypes::MAXDECIMALWIDTH) + if ((leftColWidth == datatypes::MAXDECIMALWIDTH || rightColWidth == datatypes::MAXDECIMALWIDTH) + && datatypes::isDecimal(mysqlType.colDataType)) { mysqlType.colWidth = datatypes::MAXDECIMALWIDTH; diff --git a/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.result b/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.result new file mode 100644 index 000000000..b8a31665c --- /dev/null +++ b/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.result @@ -0,0 +1,25 @@ +DROP DATABASE IF EXISTS MCOL5889; +CREATE DATABASE MCOL5889; +USE MCOL5889; +CREATE TABLE t1 (f1 DECIMAL, f2 BIGINT, f3 DOUBLE) ENGINE=columnstore; +CREATE TABLE t2 (f1 DECIMAL, f2 INT, f3 DOUBLE) ENGINE=columnstore; +INSERT INTO t1 VALUES (1, 2, 3), (2, 3, 4), (3, 4, 5); +INSERT INTO t2 VALUES (4, 5, 6), (5, 6, 7), (6, 7, 8); +SELECT f1, f2, f3, f2 * f3 FROM +( +SELECT f1, f2, AVG(f3) f3 FROM +( +SELECT f1, f2, f3 FROM t1 +UNION ALL +SELECT f1, f2, f3 FROM t2 +) U +GROUP BY f1 +) V; +f1 f2 f3 f2 * f3 +1 2 3 6 +2 3 4 12 +3 4 5 20 +4 5 6 30 +5 6 7 42 +6 7 8 56 +DROP DATABASE MCOL5889; diff --git a/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.test b/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.test new file mode 100644 index 000000000..2786ac009 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/MCOL-5889-double-is-not-decimal.test @@ -0,0 +1,24 @@ +--disable_warnings +DROP DATABASE IF EXISTS MCOL5889; +--enable_warnings +CREATE DATABASE MCOL5889; +USE MCOL5889; + +CREATE TABLE t1 (f1 DECIMAL, f2 BIGINT, f3 DOUBLE) ENGINE=columnstore; +CREATE TABLE t2 (f1 DECIMAL, f2 INT, f3 DOUBLE) ENGINE=columnstore; +INSERT INTO t1 VALUES (1, 2, 3), (2, 3, 4), (3, 4, 5); +INSERT INTO t2 VALUES (4, 5, 6), (5, 6, 7), (6, 7, 8); + +--sorted_result +SELECT f1, f2, f3, f2 * f3 FROM +( + SELECT f1, f2, AVG(f3) f3 FROM + ( + SELECT f1, f2, f3 FROM t1 + UNION ALL + SELECT f1, f2, f3 FROM t2 + ) U + GROUP BY f1 +) V; + +DROP DATABASE MCOL5889; diff --git a/tests/scripts/fullmtr.sh b/tests/scripts/fullmtr.sh index 8ed3f2133..470a03c9c 100644 --- a/tests/scripts/fullmtr.sh +++ b/tests/scripts/fullmtr.sh @@ -40,6 +40,12 @@ if (( $# == 2 )); then exit 1 fi +if (( $# == 1 )); then + run_suite $1 + exit 1 +fi + + run_suite basic run_suite bugfixes run_suite setup