Merge pull request #62984 from ClickHouse/backport/24.3/62916

Backport #62916 to 24.3: Fix PREWHERE for StorageBuffer with different source table column types.
This commit is contained in:
Nikolai Kochetov 2024-05-27 18:49:01 +02:00 committed by GitHub
commit 7b775b608d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 1 deletions

View File

@ -299,8 +299,35 @@ void StorageBuffer::read(
}
else
{
auto src_table_query_info = query_info;
if (src_table_query_info.prewhere_info)
{
auto actions_dag = ActionsDAG::makeConvertingActions(
header_after_adding_defaults.getColumnsWithTypeAndName(),
header.getColumnsWithTypeAndName(),
ActionsDAG::MatchColumnsMode::Name);
if (src_table_query_info.prewhere_info->row_level_filter)
{
src_table_query_info.prewhere_info->row_level_filter = ActionsDAG::merge(
std::move(*actions_dag->clone()),
std::move(*src_table_query_info.prewhere_info->row_level_filter));
src_table_query_info.prewhere_info->row_level_filter->removeUnusedActions();
}
if (src_table_query_info.prewhere_info->prewhere_actions)
{
src_table_query_info.prewhere_info->prewhere_actions = ActionsDAG::merge(
std::move(*actions_dag->clone()),
std::move(*src_table_query_info.prewhere_info->prewhere_actions));
src_table_query_info.prewhere_info->prewhere_actions->removeUnusedActions();
}
}
destination->read(
query_plan, columns_intersection, destination_snapshot, query_info,
query_plan, columns_intersection, destination_snapshot, src_table_query_info,
local_context, processed_stage, max_block_size, num_streams);
if (query_plan.isInitialized())

View File

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS buffer_table1__fuzz_28;
DROP TABLE IF EXISTS merge_tree_table1;
CREATE TABLE merge_tree_table1 (`x` UInt32) ENGINE = MergeTree ORDER BY x;
INSERT INTO merge_tree_table1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
SET send_logs_level='error';
CREATE TABLE buffer_table1__fuzz_28 (`x` Nullable(UInt32)) ENGINE = Buffer(currentDatabase(), 'merge_tree_table1', 16, 10, 60, 10, 1000, 1048576, 2097152);
SELECT * FROM buffer_table1__fuzz_28 PREWHERE x = toLowCardinality(1);
CREATE ROW POLICY rp ON buffer_table1__fuzz_28 FOR SELECT USING x = toLowCardinality(1) TO default;
SELECT * FROM buffer_table1__fuzz_28;