Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlglot/optimizer/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _predicate_lengths(
return

depth += 1
left, right = expression.args.values()
left, right = expression.left, expression.right

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


if isinstance(expression, exp.And if dnf else exp.Or):
for a in _predicate_lengths(left, dnf, max_, depth):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ def test_normalize(self):
"x AND (y OR z)",
)

# A multi-argument XOR is a Connector with more than two operands, which
# previously crashed predicate-length estimation with
# "ValueError: too many values to unpack". See #7698.
self.assertEqual(
normalization_distance(parse_one("(a AND b) OR XOR(c, d, e)", dialect="mysql")),
4,
)

self.check_file("normalize", normalize, schema=self.schema)

@patch("sqlglot.generator.logger")
Expand Down
Loading