Skip to content

Commit 17ca5a2

Browse files
committed
fix: sqllogictest
Signed-off-by: Kould <[email protected]>
1 parent 1b777c2 commit 17ca5a2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/query/sql/src/planner/binder/column_binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl ColumnBinding {
9393
self.source_table_index
9494
.or(self.table_index)
9595
.map(|table_index| ColumnBinding {
96-
database_name: None,
96+
database_name: self.database_name.clone(),
9797
table_name: None,
9898
column_position: self.column_position,
9999
table_index: Some(table_index),

src/query/sql/src/planner/optimizer/rule/rewrite/rule_eliminate_subquery.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,17 @@ impl Rule for RuleEliminateSubquery {
9595
let new_column_bindings = {
9696
let guard = self.metadata.read();
9797

98-
let left_columns = guard.columns_by_table_index(left_used_tables[0]);
99-
let right_columns = guard.columns_by_table_index(right_used_tables[0]);
10098
let left_table_index = left_used_tables[0];
99+
let right_table_index = right_used_tables[0];
100+
let left_columns = guard.columns_by_table_index(left_table_index);
101+
let right_columns = guard.columns_by_table_index(right_table_index);
101102
let left_table = guard.table(left_table_index);
103+
// filter table function
104+
if left_table.database() == "system"
105+
|| guard.table(right_table_index).database() == "system"
106+
{
107+
return Ok(());
108+
}
102109
let left_source_table_index = guard
103110
.get_source_table_index(Some(left_table.database()), left_table.table().name());
104111

@@ -270,6 +277,19 @@ impl VisitorMut<'_> for ExprAsSourceVisitor {
270277
self.failed = true;
271278
return Ok(());
272279
};
280+
if binding.source_table_index.or(binding.table_index).is_none()
281+
|| binding.column_position.is_none()
282+
{
283+
self.failed = true;
284+
return Ok(());
285+
}
286+
// filter table function
287+
if matches!(
288+
binding.database_name.as_ref().map(String::as_ref),
289+
Some("system")
290+
) {
291+
return Ok(());
292+
}
273293
col.column = binding;
274294
Ok(())
275295
}

tests/sqllogictests/suites/query/subquery.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,28 @@ WHERE t1.i1 = (
946946
statement ok
947947
create or replace table t1(a int, b int, c varchar(20));
948948

949+
statement ok
950+
create or replace table t2(a int, b int, c varchar(20));
951+
949952
statement ok
950953
insert into t1 (a, b, c) values (1, 7, 'D'), (2, 7, 'D'), (3, 7, 'D'), (4, 8, 'D'), (5, 7, 'E'), (6, 8, 'E');
951954

955+
statement ok
956+
insert into t2 (a, b, c) VALUES (10, 7, 'X'), (11, 7, 'Y'), (12, 8, 'Z'), (13, 9, 'W');
957+
952958
query T
953959
select t3.* from t1 as t3 where t3.c = 'D' and t3.a in (select t4.a from t1 as t4 where t4.b = 7);
954960
----
955961
1 7 D
956962
2 7 D
957963
3 7 D
964+
965+
query T rowsort
966+
select * from t1 as t3 inner join t2 as t5 on t3.b = t5.b where t3.c = 'D' and t3.a in (select t4.a from t1 as t4 where t4.b = 7);
967+
----
968+
1 7 D 10 7 X
969+
1 7 D 11 7 Y
970+
2 7 D 10 7 X
971+
2 7 D 11 7 Y
972+
3 7 D 10 7 X
973+
3 7 D 11 7 Y

0 commit comments

Comments
 (0)