Repository navigation
Conversation
Author
|
Hi @jayzhan211, this is my first contribution to DataFusion so the CI workflows are waiting for approval. Could you please approve them when you have a chance? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
An
EXISTS/NOT EXISTSsubquery that unnests the result of a correlated aggregate withoutGROUP BY(such ascount(*)) drops outer rows that have no matching inner rows:PullUpCorrelatedExpraddsi.ato theGROUP BYof the aggregate, so unmatched outer rows produce no rows from the aggregate. WhenLogicalPlan::Unnestseescollected_count_expr_mapon its input, it setscan_pull_up = false;build_jointhen retriesEXISTSwithout count-bug handling, wherecollected_count_expr_mapis empty, allowing the uncompensatedLeftSemijoin to proceed and drop unmatched outer rows.Similarly, for
IN/NOT INoverUnnestof a groupless aggregate,count_bug_is_harmlessdid not checkpull_up.can_pull_up, treating shapes rejected byUnnestas harmless whencollected_count_expr_maphad no entry for the top plan.What changes are included in this PR?
PullUpCorrelatedExpr::pull_up_unnestindatafusion/optimizer/src/decorrelate.rs:EXISTSfallback retry from pulling up throughUnnestover a regrouped scalar aggregate.EXISTS/NOT EXISTS/IN/NOT IN) with count-bug handling enabled, evaluates single-column depth-1 listUnneston empty-input aggregate values:make_array()), no count bug survives aboveUnnest.make_array(0),make_array(0, 0),make_array(NULL)), propagates the uniform element value intocollected_count_expr_map. ForEXISTS, requires thatUnnestcannot drop matched rows (otherwise a matched group yielding 0 rows would be indistinguishable from an unmatched outer row in aLEFT JOIN), and tracks whenUnnestmay emit multiple rows per group (unnest_may_multiply_rows).LATERALjoins unchanged.build_join/build_join_with_count_bugindatafusion/optimizer/src/decorrelate_predicate_subquery.rs:unnest_may_multiply_rowsis set and there is noHAVINGor outer filter above the aggregate, skips theLEFT JOIN(avoiding duplicate outer rows) and emits the unconditionalEXISTS = trueplan; when combined with a filter aboveUnnest, keeps the subquery correlated.pull_up.can_pull_upincount_bug_is_harmlessforIN/NOT IN.What is the testing strategy for this PR?
Added
sqllogictestcases indatafusion/sqllogictest/test_files/subquery.sltcovering:#27829reproducer (EXISTS,NOT EXISTS, and projectedEXISTSoverunnest(make_array(c, c))).Unnestqueries from fix: update join schema when pulling up correlated columns #27783 (INoverunnest(make_array(max(a))),EXISTSoverunnest(make_array(c))withWHERE v > 0) continuing to return the same rows.Unnestsatisfied byc = 0(WHERE v = 0).make_array()).Unnestwith a filter or outer filter above, distinct elements (make_array(c, c + 1)),CASEexpressions that can produce an empty array for matched rows,NOT INovermax(a), andINovercount(*).Are there any user-facing changes?
EXISTS/NOT EXISTSsubqueries overUnnestof a correlated groupless aggregate now return correct results (or a not-implemented error for unsupported shapes) instead of silently dropping or returning wrong rows. No public API changes.