Repository navigation
Conversation
…ns it A projection names each item by setting the alias on its expression, and a variable reference binds to the scope's own object. When x + 0, x * 1, x - 0 or x / 1 simplified to that object, the item's alias renamed the variable: WITH x + 0 AS y, x RETURN y, x and RETURN x, x + 0 each returned two columns named x. An arithmetic identity over a scope expression now stays as written, so the alias lands on it. A scope expression is also never simplified again, and NOT NOT no longer unwraps a NOT from the scope. Otherwise a nested reference to a kept expression, e.g. CASE WHEN true THEN m END after WITH n + 0 AS m, was simplified into an operand that is no longer in scope, which ran an aggregate again or failed to evaluate. Boolean and CASE simplifications still return the operand and still rename it, as WITH x AS y, x does; that is unchanged. Property references are copies, so n.id + 0 = 1 still becomes an index lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
This work was produced with the help of language models.
Fixes #1247.
UNWIND [1, 2] AS x WITH x + 0 AS y, x RETURN y, xreturned two columns namedx, as didRETURN x, x + 0. A projection names each item by setting the alias on its expression, and a variable reference binds to the scope's own object, so whenx + 0,x * 1,x - 0orx / 1simplified to that object, the alias renamed the variable.Fix. An arithmetic identity over a scope expression stays as written, so the alias lands on
+(x,0). A scope expression is also never simplified again, andNOT NOTdoes not unwrap aNOTtaken from the scope; either would return a part of the kept expression that is no longer in scope:CASE WHEN true THEN m ENDafterWITH n + 0 AS mthen ran the aggregate again, andNOT zafterWITH NOT b AS zfails onmaintoday with "Cannot evaluate expression with type VARIABLE". Boolean, CASE and cast simplifications still return the operand and still rename it, as plainWITH x AS y, xdoes; that is unchanged and tracked in #1287. Property references are copies, son.id + 0 = 1still becomes an index lookup.Tests.
projection/simplified_variable_alias.test:ArithmeticIdentityOverVariableKeepsAliaschecks the column names of the issue's three queries and ofRETURN x, x + 0; onmainthey arex, x,m, m,x, x.SimplifiedScopeExpressionReferencedLaterandSimplifiedNodeStaysPatternreference a keptx + 0,b AND true,NOT bor node from a laterCASE,AND,NOT,ORDER BYorMATCH; theNOT zquery fails onmain, the rest pin the two rules. Full suite: no failures.