Skip to content

Commit 467a804

Browse files
authored
Report offending plan node when In/Exist subquery misused (#13155)
1 parent 0b45b9a commit 467a804

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

datafusion/optimizer/src/analyzer/subquery.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ pub fn check_subquery_expr(
113113
| LogicalPlan::Join(_) => Ok(()),
114114
_ => plan_err!(
115115
"In/Exist subquery can only be used in \
116-
Projection, Filter, Window functions, Aggregate and Join plan nodes"
116+
Projection, Filter, Window functions, Aggregate and Join plan nodes, \
117+
but was used in [{}]",
118+
outer_plan.display()
117119
),
118120
}?;
119121
check_correlations_in_subquery(inner_plan)

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
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\]
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)