You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2026-01-06 08:21:10 +03:00
After an AggreateColumn corresponding to SUM(1+1) is created,
it is pushed to the list:
gwi.count_asterisk_list.push_back(ac)
Later, in getSelectPlan(), the expression SUM(1+1) was erroneously
treated as a constant:
if (!hasNonSupportItem && !nonConstFunc(ifp) && !(parseInfo & AF_BIT) && tmpVec.size() == 0)
{
srcp.reset(buildReturnedColumn(item, gwi, gwi.fatalParseError));
This code freed the original AggregateColumn and replaced to a ConstantColumn.
But gwi.count_asterisk_list still pointer to the freed AggregateColumn().
The expression SUM(1+1) was treated as a constant because tmpVec
was empty due to a bug in this code:
// special handling for count(*). This should not be treated as constant.
if (isp->argument_count() == 1 &&
( sfitempp[0]->type() == Item::CONST_ITEM &&
(sfitempp[0]->cmp_type() == INT_RESULT ||
sfitempp[0]->cmp_type() == STRING_RESULT ||
sfitempp[0]->cmp_type() == REAL_RESULT ||
sfitempp[0]->cmp_type() == DECIMAL_RESULT)
)
)
{
field_vec.push_back((Item_field*)item); //dummy
Notice, it handles only aggregate functions with explicit literals
passed as an argument, while it does not handle constant expressions
such as 1+1.
Fix:
- Adding new classes ConstantColumnNull, ConstantColumnString,
ConstantColumnNum, ConstantColumnUInt, ConstantColumnSInt,
ConstantColumnReal, ValStrStdString, to reuse the code easier.
- Moving a part of the code from the case branch handling CONST_ITEM
in buildReturnedColumn() into a new function
newConstantColumnNotNullUsingValNativeNoTz(). This
makes the code easier to read and to reuse in the future.
- Adding a new function newConstantColumnMaybeNullFromValStrNoTz().
Removing dulplicate code from !!!four!!! places, using the new
function instead.
- Adding a function isSupportedAggregateWithOneConstArg() to
properly catch all constant expressions. Using the new function parse_item()
in the code commented as "special handling for count(*)".
Now it pushes all constant expressions to field_vec, not only
explicit literals.
- Moving a part of the code from buildAggregateColumn()
to a helper function processAggregateColumnConstArg().
Using processAggregateColumnConstArg() in the CONST_ITEM
and NULL_ITEM branches.
- Adding a new branch in buildReturnedColumn() handling FUNC_ITEM.
If a function has constant arguments, a ConstantColumn() is
immediately created, without going to
buildArithmeticColumn()/buildFunctionColumn().
- Reusing isSupportedAggregateWithOneConstArg()
and processAggregateColumnConstArg() in buildAggregateColumn().
A new branch catches aggregate function has only one constant argument
and immediately creates a single ConstantColumn without
traversing to the argument sub-components.
64 lines
1.0 KiB
Plaintext
64 lines
1.0 KiB
Plaintext
DROP DATABASE IF EXISTS mcol_4728;
|
|
CREATE DATABASE mcol_4728;
|
|
USE mcol_4728;
|
|
SET columnstore_select_handler=ON;
|
|
CREATE TABLE t1 (a INT) ENGINE=ColumnStore;
|
|
SELECT SUM(0+0)-SUM(0+0) FROM t1;
|
|
SUM(0+0)-SUM(0+0)
|
|
NULL
|
|
SELECT SUM(0) FROM t1;
|
|
SUM(0)
|
|
NULL
|
|
SELECT COUNT(0) FROM t1;
|
|
COUNT(0)
|
|
0
|
|
SELECT COUNT(NULL) FROM t1;
|
|
COUNT(NULL)
|
|
0
|
|
SELECT COUNT(COALESCE(NULL)) FROM t1;
|
|
COUNT(COALESCE(NULL))
|
|
0
|
|
SELECT MAX(0) FROM t1;
|
|
MAX(0)
|
|
NULL
|
|
SELECT SUM(1)+1 FROM t1;
|
|
SUM(1)+1
|
|
NULL
|
|
SELECT SUM(COALESCE(1))+1 FROM t1;
|
|
SUM(COALESCE(1))+1
|
|
NULL
|
|
SELECT sum(rand(0))+1 FROM t1;
|
|
sum(rand(0))+1
|
|
NULL
|
|
INSERT INTO t1 VALUES (100);
|
|
SELECT SUM(0+0)-SUM(0+0) FROM t1;
|
|
SUM(0+0)-SUM(0+0)
|
|
0
|
|
SELECT SUM(0) FROM t1;
|
|
SUM(0)
|
|
0
|
|
SELECT COUNT(0) FROM t1;
|
|
COUNT(0)
|
|
1
|
|
SELECT COUNT(NULL) FROM t1;
|
|
COUNT(NULL)
|
|
0
|
|
SELECT COUNT(COALESCE(NULL)) FROM t1;
|
|
COUNT(COALESCE(NULL))
|
|
0
|
|
SELECT MAX(0) FROM t1;
|
|
MAX(0)
|
|
0
|
|
SELECT SUM(1)+1 FROM t1;
|
|
SUM(1)+1
|
|
2
|
|
SELECT SUM(COALESCE(1))+1 FROM t1;
|
|
SUM(COALESCE(1))+1
|
|
2
|
|
SELECT sum(rand(0))+1 FROM t1;
|
|
sum(rand(0))+1
|
|
1.1552204276949358
|
|
DROP TABLE t1;
|
|
DROP DATABASE mcol_4728;
|
|
USE test;
|