-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-45752][SQL] Simplify the code for check unreferenced CTE relations #43727
Conversation
b39bdcd
to
ab994ec
Compare
if (refCount == 0) { | ||
checkUnreferencedCTERelations(cteMap, visited, cteId) | ||
} | ||
if (refCount == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this misses some corners cases. For example
WITH
a as (select * from table_exists),
b as (select * from a),
c as (select * from table_non_exists),
d as (select * from c)
SELECT 1
So the code may only check a
and b
but lose the checking over c
and d
.
cc @cloud-fan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean your current change may not be able to handle the proposed case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the test case passed.
ab994ec
to
8821a0d
Compare
// If a CTE relation is never used, it will disappear after inline. Here we explicitly check | ||
// analysis for it, to make sure the entire query plan is valid. | ||
try { | ||
// If a CTE relation ref count is 0, the other CTE relations that reference it | ||
// should also be checked by checkAnalysis0. This code will also guarantee the leaf | ||
// relations that do not reference any others are checked first. | ||
val visited: mutable.Map[Long, Boolean] = mutable.Map.empty.withDefaultValue(false) | ||
cteMap.foreach { case (cteId, _) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't realize that we were doing a nested loop before, good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right nice catch!
Merged to master |
late LGTM. Thank you @beliefer |
What changes were proposed in this pull request?
#43614 let unreferenced
CTE
checked byCheckAnalysis0
.This PR follows up #43614 to simplify the code for check unreferenced CTE relations.
Why are the changes needed?
Simplify the code for check unreferenced CTE relations
Does this PR introduce any user-facing change?
'No'.
How was this patch tested?
Exists test cases.
Was this patch authored or co-authored using generative AI tooling?
'No'.