fix(optimizer): handle multi-arg XOR in normalize predicate lengths [CLAUDE]#7699
Closed
code-with-rashid wants to merge 1 commit into
Closed
fix(optimizer): handle multi-arg XOR in normalize predicate lengths [CLAUDE]#7699code-with-rashid wants to merge 1 commit into
code-with-rashid wants to merge 1 commit into
Conversation
_predicate_lengths unpacked `expression.args.values()`, assuming every Connector has exactly two operands. A function-form XOR(a, b, c) is a Connector with more than two args, so normalize crashed with "ValueError: too many values to unpack (expected 2)". Use the canonical Connector.left/right accessors instead. Closes tobymao#7698 CLAUDE
georgesittas
reviewed
Jun 3, 2026
|
|
||
| depth += 1 | ||
| left, right = expression.args.values() | ||
| left, right = expression.left, expression.right |
Collaborator
There was a problem hiding this comment.
Why are we only getting left and right, given the presence of the other XOR operands? Isn't this effectively discarding the rest of them?
Also, I don't think MySQL supports XOR(c, d, e):
Server version: 9.6.0 Homebrew
mysql> select xor(1, 2, 3);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xor(1, 2, 3)' at line 1
Collaborator
|
I think this PR is just treating a symptom. I'll give this a whirl, I think assigning |
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.
Problem
normalizecrashes withValueError: too many values to unpack (expected 2)on boolean expressions containing a function-formXOR(...):Closes #7698.
Cause
_predicate_lengths()didleft, right = expression.args.values(), assuming everyexp.Connectorhas exactly two operands (this,expression). That holds forAnd/Orand binarya XOR b, butXoris also aFunc, so the function formXOR(a, b, c)parses to aConnectorwhoseargsalso includeexpressions(andround_input) — more than two values — and the unpack fails.Fix
Use the canonical
Connector.left/Connector.rightaccessors instead of unpacking the raw args dict. Behavior is unchanged for all two-operand connectors; multi-argXorno longer crashes.Tests
Added a regression assertion to
test_normalizeexercisingnormalization_distanceon(a AND b) OR XOR(c, d, e).python -m unittest tests.test_optimizerpasses (79 tests);ruffandmypyare clean.Disclosure: prepared with the assistance of an AI agent (model: Claude), per the repository's contributor policy.