The NEED_PREPARE do not call part_log_writer() before.
v2:
- Add a test for missed entries in system.part_log for merge
- Fix part_log_writer
- Add a test for missed entries in system.part_log for mutate
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Fixes:
select toNullable(os_name) AS os_name, count() from (SELECT CAST('iphone' AS Enum8('iphone' = 1, 'android' = 2)) AS os_name) group by os_name WITH TOTALS settings allow_experimental_analyzer=1
Code: 10. DB::Exception: Received from localhost:9000. DB::Exception: Not found column __table1.os_name: in block toNullable(__table1.os_name) Nullable(Enum8('iphone' = 1, 'android' = 2)) Nullable(size = 0, Int8(size = 0), UInt8(size = 0)), count() UInt64 UInt64(size = 0). (NOT_FOUND_COLUMN_IN_BLOCK)
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
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>