fix(sql): exception thrown when same DECLARE variable used in 2-params function #5806
fix(sql): exception thrown when same DECLARE variable used in 2-params function #5806bluestreak01 merged 5 commits intomasterfrom
Conversation
…arison confusion in PostOrderTreeTraversalAlgo
nwoolmer
left a comment
There was a problem hiding this comment.
nit: title could be more descriptive of the problem, for example:
"fix(sql): exception thrown when duplicate DECLARE variables appear in function argument lists"
Explaining more what the problem was, rather than how you fixed it!
bluestreak01
left a comment
There was a problem hiding this comment.
thank you for picking up and diagnosing this issue so quickly!
While the fix works in this particular instance, I would encourage you to consider a different perspective:
- post order traversal algo is essentially defective, it doesn't handle
lhsandrhsbeing the same object references - instead of fixing the algo defect we are conforming a particular "user" of this algo to fudge different object instance even in cases where it isn't necessary
- there are many other "users" of this algo that are unaware of the algo limitation can either experience this issue at runtime or sometime in the future making someone else debug the same issue
You should be able to vibe-fix this algo with AI (Claude) in 5 min and not create clone of args now or ever in the future.
What do you think?
The author proposed both solutions at first. I thought that fixing this case in isolation was a safe bet for 9.0.0, which could be followed up with the wider reaching algo fix afterwards. |
Got it, I will do so.
That was my initial approach (see related patch) but after discussing with Nick, we agreed that this patch was too invasive for such a specific case. After discussions, we will fix the |
[PR Coverage check]😍 pass : 5 / 5 (100.00%) file detail
|
This PR fixes #5804 by deepCloning
ExpressionNodes that are used to replace variables.When SqlParser replaces declare variables with constant expressions, it was re-using the original
ExpressionNodeinstances instead of cloning them. BecausePostOrderTreeTraversalAlgorelies on reference comparison to track traversal state, sharing the same node instance between the lhs and rhs of an expression can trick the algorithm into thinking it has already processed lhs.The problematic check:
Example of a failing query: