Skip to content

Commit e52187e

Browse files
committed
fix: push_down_filter optimization pass can push a IN(<subquery>) into a TableScan's filter clause
1 parent fbc9c46 commit e52187e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

datafusion/expr/src/logical_plan/invariants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ pub fn check_subquery_expr(
210210
match outer_plan {
211211
LogicalPlan::Projection(_)
212212
| LogicalPlan::Filter(_)
213+
| LogicalPlan::TableScan(_)
213214
| LogicalPlan::Window(_)
214215
| LogicalPlan::Aggregate(_)
215216
| LogicalPlan::Join(_) => Ok(()),
216217
_ => plan_err!(
217218
"In/Exist subquery can only be used in \
218-
Projection, Filter, Window functions, Aggregate and Join plan nodes, \
219+
Projection, Filter, TableScan, Window functions, Aggregate and Join plan nodes, \
219220
but was used in [{}]",
220221
outer_plan.display()
221222
),

datafusion/sqllogictest/test_files/subquery.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ SELECT t1_id, t1_name, t1_int, (select t2_id, t2_name FROM t2 WHERE t2.t2_id = t
438438

439439
#subquery_not_allowed
440440
#In/Exist Subquery is not allowed in ORDER BY clause.
441-
statement error DataFusion error: check_analyzed_plan\ncaused by\nError during planning: In/Exist subquery can only be used in Projection, Filter, Window functions, Aggregate and Join plan nodes, but was used in \[Sort: t1.t1_int IN \(<subquery>\) ASC NULLS LAST\]
441+
statement error DataFusion error: check_analyzed_plan\ncaused by\nError during planning: In/Exist subquery can only be used in Projection, Filter, TableScan, Window functions, Aggregate and Join plan nodes, but was used in \[Sort: t1.t1_int IN \(<subquery>\) ASC NULLS LAST\]
442442
SELECT t1_id, t1_name, t1_int FROM t1 order by t1_int in (SELECT t2_int FROM t2 WHERE t1.t1_id > t1.t1_int)
443443

444444
#non_aggregated_correlated_scalar_subquery

0 commit comments

Comments
 (0)