Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default value used in row level filter #43387

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,17 @@ MergeTreeReadTaskColumns getReadTaskColumns(
/// 1. Columns for row level filter
if (prewhere_info->row_level_filter)
{
Names row_filter_column_names = prewhere_info->row_level_filter->getRequiredColumnsNames();
Names row_filter_column_names = prewhere_info->row_level_filter->getRequiredColumnsNames();
injectRequiredColumns(
data_part_info_for_reader, storage_snapshot, with_subcolumns, row_filter_column_names);
result.pre_columns.push_back(storage_snapshot->getColumnsByNames(options, row_filter_column_names));
pre_name_set.insert(row_filter_column_names.begin(), row_filter_column_names.end());
}

/// 2. Columns for prewhere
Names all_pre_column_names = prewhere_info->prewhere_actions->getRequiredColumnsNames();

const auto injected_pre_columns = injectRequiredColumns(
injectRequiredColumns(
data_part_info_for_reader, storage_snapshot, with_subcolumns, all_pre_column_names);

for (const auto & name : all_pre_column_names)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- { echoOn }

SELECT a, c FROM test_rlp WHERE c%2 == 0 AND b < 5;
0 10
2 12
4 14
DROP POLICY IF EXISTS test_rlp_policy ON test_rlp;
CREATE ROW POLICY test_rlp_policy ON test_rlp FOR SELECT USING c%2 == 0 TO default;
SELECT a, c FROM test_rlp WHERE b < 5 SETTINGS optimize_move_to_prewhere = 0;
0 10
2 12
4 14
SELECT a, c FROM test_rlp PREWHERE b < 5;
0 10
2 12
4 14
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
DROP TABLE IF EXISTS test_rlp;

CREATE TABLE test_rlp (a Int32, b Int32) ENGINE=MergeTree() ORDER BY a SETTINGS index_granularity=5;

INSERT INTO test_rlp SELECT number, number FROM numbers(15);

ALTER TABLE test_rlp ADD COLUMN c Int32 DEFAULT b+10;

-- { echoOn }

SELECT a, c FROM test_rlp WHERE c%2 == 0 AND b < 5;

DROP POLICY IF EXISTS test_rlp_policy ON test_rlp;

CREATE ROW POLICY test_rlp_policy ON test_rlp FOR SELECT USING c%2 == 0 TO default;

SELECT a, c FROM test_rlp WHERE b < 5 SETTINGS optimize_move_to_prewhere = 0;

SELECT a, c FROM test_rlp PREWHERE b < 5;

-- { echoOff }

DROP POLICY test_rlp_policy ON test_rlp;

DROP TABLE test_rlp;