ClickHouse/tests/queries/0_stateless/02992_analyzer_group_by_const.reference

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

9 lines
122 B
Plaintext
Raw Normal View History

Fix function execution over const and LowCardinality with GROUP BY const for analyzer Consider the following example: SELECT concatWithSeparator('|', 'a', concatWithSeparator('|', CAST('x', 'LowCardinality(String)'))) GROUP BY 'a' Under analyzer it fails, UBsan report: ==15121==WARNING: MemorySanitizer: use-of-uninitialized-value ... 8 0x5555601880ed in void DB::FormatStringImpl::format<true, false>() /src/ch/clickhouse/src/Functions/formatString.h:125:21 9 0x55556017aeb8 in void DB::FormatStringImpl::formatExecute<>() /src/ch/clickhouse/src/Functions/formatString.h:30:13 10 0x555560196779 in DB::()::ConcatWithSeparatorImpl<>::executeImpl() const /src/ch/clickhouse/src/Functions/concatWithSeparator.cpp:151:9 11 0x55555a2ad5b7 in DB::FunctionToExecutableFunctionAdaptor::executeImpl() const /src/ch/clickhouse/src/Functions/IFunctionAdaptor.h:21:26 12 0x555584312297 in DB::IExecutableFunction::executeWithoutLowCardinalityColumns() const /src/ch/clickhouse/src/Functions/IFunction.cpp:249:15 13 0x555584317640 in DB::IExecutableFunction::executeWithoutSparseColumns() const /src/ch/clickhouse/src/Functions/IFunction.cpp:283:24 14 0x55558431bf5c in DB::IExecutableFunction::execute() const /src/ch/clickhouse/src/Functions/IFunction.cpp:380:16 15 0x555587bf3e20 in DB::executeAction() /src/ch/clickhouse/src/Interpreters/ExpressionActions.cpp:613:60 Uninitialized value was created by a heap allocation ... 6 0x55558b1c1a05 in DB::ColumnString::reserve(unsigned long) /src/ch/clickhouse/src/Columns/ColumnString.cpp:494:13 7 0x55558980095d in DB::prepareOutputBlockColumns() /src/ch/clickhouse/src/Interpreters/AggregationUtils.cpp:32:25 The problem is that during query analysis (QueryAnalyzer::resolveFunction()), the return value of the function had been executed as LowCardinality(String), but the 'a' argument that is passed to the concatWithSeparator() is not-const, because it had been reused from the GROUP BY step, and this causes UB, since column 'a' does not have enough rows (it should have 2 rows, since LowCardinality always contains the default, while it has only 1). v2: fix GROUPING SETs Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2024-02-14 13:58:49 +00:00
b
a|a
a|x
String, Const(size = 1, String(size = 1))
String, Const(size = 1, String(size = 1))
5128475243952187658
0 0
0 0