From 8dd2f2937cc1957bbd23820d2ec63b0b92534313 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Tue, 11 May 2021 22:16:43 +0300 Subject: [PATCH] MCOL-4407 and condtion does not work when HWM > columnstore_string_scan_threshold - 1 --- .../columnstore/bugfixes/mcol-4407.result | 32 ++++++++++++++ .../columnstore/bugfixes/mcol-4407.test | 44 +++++++++++++++++++ primitives/linux-port/dictionary.cpp | 18 ++++++++ 3 files changed, 94 insertions(+) create mode 100644 mysql-test/columnstore/bugfixes/mcol-4407.result create mode 100644 mysql-test/columnstore/bugfixes/mcol-4407.test diff --git a/mysql-test/columnstore/bugfixes/mcol-4407.result b/mysql-test/columnstore/bugfixes/mcol-4407.result new file mode 100644 index 000000000..031934208 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-4407.result @@ -0,0 +1,32 @@ +DROP DATABASE IF EXISTS mcol_4407; +CREATE DATABASE mcol_4407; +USE mcol_4407; +DROP TABLE IF EXISTS `sictable`; +/* Bug when HWM > scan_threshold - 1 */ +set max_recursive_iterations=6282; +CREATE TABLE `sictable` + ( +`serialno` VARCHAR(20) NOT NULL +) +ENGINE=Columnstore +DEFAULT CHARSET=utf8 +; +INSERT INTO `sictable` ( +with recursive series as ( +select 1 as id union all +select id +1 as id from series +where id < 6281) +select lpad(id,11,'0') from series); +SELECT `serialno` +FROM `sictable` +WHERE `serialno` = '00000000029' AND `serialno` = '00000006256'; +serialno +SELECT `serialno` +FROM `sictable` +WHERE `serialno` = '00000000029' AND `serialno` = '00000000029'; +serialno +00000000029 +/* Default value */ +set max_recursive_iterations=1000; +DROP TABLE `sictable`; +DROP DATABASE mcol_4407; diff --git a/mysql-test/columnstore/bugfixes/mcol-4407.test b/mysql-test/columnstore/bugfixes/mcol-4407.test new file mode 100644 index 000000000..a834fb5bf --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-4407.test @@ -0,0 +1,44 @@ +--source ../include/have_columnstore.inc + +-- disable_warnings +DROP DATABASE IF EXISTS mcol_4407; +-- enable_warnings + +CREATE DATABASE mcol_4407; +USE mcol_4407; + +-- disable_warnings +DROP TABLE IF EXISTS `sictable`; +-- enable_warnings + +/* Bug when HWM > scan_threshold - 1 */ +set max_recursive_iterations=6282; + +CREATE TABLE `sictable` + ( + `serialno` VARCHAR(20) NOT NULL + ) + ENGINE=Columnstore + DEFAULT CHARSET=utf8 + ; + +INSERT INTO `sictable` ( +with recursive series as ( +select 1 as id union all +select id +1 as id from series +where id < 6281) +select lpad(id,11,'0') from series); + +SELECT `serialno` +FROM `sictable` +WHERE `serialno` = '00000000029' AND `serialno` = '00000006256'; + +SELECT `serialno` +FROM `sictable` +WHERE `serialno` = '00000000029' AND `serialno` = '00000000029'; + +/* Default value */ +set max_recursive_iterations=1000; + +DROP TABLE `sictable`; +DROP DATABASE mcol_4407; diff --git a/primitives/linux-port/dictionary.cpp b/primitives/linux-port/dictionary.cpp index 2403cc99b..3b9cc6420 100644 --- a/primitives/linux-port/dictionary.cpp +++ b/primitives/linux-port/dictionary.cpp @@ -495,6 +495,24 @@ void PrimitiveProcessor::p_Dictionary(const DictInput* in, if (eqFilter) { + // MCOL-4407. + // Support filters: + // `where key = value0 and key = value1 {and key = value2}` + // + // The problem occurs only when HWM > columnstore_string_scan_threshold - 1 + // because in this case: + // CS uses `tryCombineDictionary` which combines `DictStep`s into one as result + // `eqFilter` has more than 1 filter and applies the logic below which is `or` by + // default. + // Note: The case HWM <= columnstore_string_scan_threshold - 1 has the same problem, + // function `p_TokenByScan`, but it does not occur because `tryCombineDictionaryScan` + // was turned off. + if (eqFilter->size() > 1 && in->BOP == BOP_AND && eqOp == COMPARE_EQ) + goto no_store; + + if (eqFilter->size() > 1 && in->BOP == BOP_OR && eqOp == COMPARE_NE) + goto store; + // MCOL-1246 Trim whitespace before match string strData((char*)sigptr.data, sigptr.len); boost::trim_right_if(strData, boost::is_any_of(" "));