From 17c341105e8549eaeec61b60cdd2dd0c57657f0e Mon Sep 17 00:00:00 2001 From: "xudong.w" Date: Tue, 11 Jun 2024 19:26:28 +0800 Subject: [PATCH] fix: lazy materialization does not support set operation (#15754) * fix: lazy materialization does not support set operation * add tests --- .../executor/physical_plans/physical_table_scan.rs | 14 ++++++-------- tests/sqllogictests/suites/query/union.test | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/query/sql/src/executor/physical_plans/physical_table_scan.rs b/src/query/sql/src/executor/physical_plans/physical_table_scan.rs index 65036e176c1d..ad9305b4da76 100644 --- a/src/query/sql/src/executor/physical_plans/physical_table_scan.rs +++ b/src/query/sql/src/executor/physical_plans/physical_table_scan.rs @@ -179,16 +179,14 @@ impl PhysicalPlanBuilder { let internal_column = INTERNAL_COLUMN_FACTORY .get_internal_column(ROW_ID_COL_NAME) .unwrap(); - let index = self + if let Some(index) = self .metadata .read() - .row_id_index_by_table_index(scan.table_index); - debug_assert!(index.is_some()); - // Safe to unwrap: if lazy_columns is not empty, the `analyze_lazy_materialization` have been called - // and the row_id index of the table_index has been generated. - let index = index.unwrap(); - entry.insert(index); - project_internal_columns.insert(index, internal_column); + .row_id_index_by_table_index(scan.table_index) + { + entry.insert(index); + project_internal_columns.insert(index, internal_column); + } } } diff --git a/tests/sqllogictests/suites/query/union.test b/tests/sqllogictests/suites/query/union.test index 4348ec255e88..00c2d9b3c7f8 100644 --- a/tests/sqllogictests/suites/query/union.test +++ b/tests/sqllogictests/suites/query/union.test @@ -276,5 +276,19 @@ SELECT ---- 10086 +statement ok +create or replace table t (n bigint); + +statement ok +insert into t (n) values (1); + +query I +with t1 as (SELECT user_id AS root_uid FROM test4 where parent is not null limit 2), t2 as (SELECT 10086 AS root_uid from t limit 200) select * from t1 union all select * from t2; +---- +10086 + statement ok drop table test4; + +statement ok +drop table t;