Skip to content

Commit

Permalink
Backport #61971 to 24.1: Crash in Engine Merge if Row Policy does not…
Browse files Browse the repository at this point in the history
… have expression
  • Loading branch information
robot-clickhouse committed Apr 3, 2024
1 parent d0c9c0d commit a682a19
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Storages/StorageMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ std::vector<ReadFromMerge::ChildPlan> ReadFromMerge::createChildrenPlans(SelectQ
database_name,
table_name,
RowPolicyFilterType::SELECT_FILTER);
if (row_policy_filter_ptr)
if (row_policy_filter_ptr && !row_policy_filter_ptr->empty())
{
row_policy_data_opt = RowPolicyData(row_policy_filter_ptr, storage, context);
row_policy_data_opt->extendNames(real_column_names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ SELECT x, y from merge(currentDatabase(), 02763_merge
4 14
4 14
4 14
USING 0
USING 1
zzz
====
SETTINGS optimize_move_to_prewhere= 1
SELECT * FROM 02763_merge_log_1
3 13
Expand Down Expand Up @@ -312,3 +316,7 @@ SELECT x, y from merge(currentDatabase(), 02763_merge
4 14
4 14
4 14
USING 0
USING 1
zzz
====
23 changes: 23 additions & 0 deletions tests/queries/0_stateless/02763_row_policy_storage_merge.sql.j2
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ SELECT x, lc, cnst from merge(currentDatabase(), '02763_merge_fancycols') ORDER
SELECT 'SELECT x, y from merge(currentDatabase(), 02763_merge';
SELECT x, y from merge(currentDatabase(), '02763_merge') ORDER BY x SETTINGS optimize_move_to_prewhere= {{prew}};



CREATE TABLE 02763_t1 ( b String ) ENGINE = MergeTree() ORDER BY tuple();
INSERT INTO 02763_t1 VALUES('zzz');
CREATE TABLE 02763_t2 AS 02763_t1 ENGINE = Merge(currentDatabase(), '02763_t1');

SELECT 'USING 0';
CREATE ROW POLICY OR REPLACE 02763_filter_t1 ON 02763_t1 USING 0 TO ALL;
SELECT * FROM 02763_t2 SETTINGS optimize_move_to_prewhere= {{prew}};

SELECT 'USING 1';
CREATE ROW POLICY OR REPLACE 02763_filter_t1 ON 02763_t1 USING 1 TO ALL;
SELECT * FROM 02763_t2 SETTINGS optimize_move_to_prewhere= {{prew}};


DROP TABLE 02763_t1;
DROP TABLE 02763_t2;
SELECT '====';



DROP TABLE 02763_merge_fancycols;

DROP ROW POLICY 02763_filter_1 ON 02763_merge_log_1;
Expand All @@ -140,4 +161,6 @@ DROP ROW POLICY 02763_filter_4 ON 02763_merge_merge_1;
DROP ROW POLICY 02763_filter_5 ON 02763_merge_fancycols;
DROP ROW POLICY 02763_filter_6 ON 02763_merge_fancycols;

DROP ROW POLICY 02763_filter_t1 ON 02763_t1;

{% endfor %}

0 comments on commit a682a19

Please sign in to comment.