The GitHub Actions job "Nightly - CI" on shardingsphere.git/master has failed.
Run started by GitHub user menghaoranss (triggered by menghaoranss).

Head commit for run:
1a40be57d95c63383a7cce0a557951e522b8d07b / Rain. 
<[email protected]>
Fix MySQL OR and XOR operator precedence (#40329)

* Fix MySQL OR and XOR operator precedence

MySQL's operator precedence table ranks XOR above OR (AND > XOR > OR), but the
MySQL grammar listed the `expr orOperator expr` alternative ahead of
`expr XOR expr`. ANTLR4 resolves the alternatives of a directly left-recursive
rule by their order, with the earlier alternative binding tighter, so OR
outranked XOR:

  1 OR 1 XOR 1  ->  (1 OR 1) XOR 1     (wrong)
  1 XOR 1 OR 1  ->  1 XOR (1 OR 1)     (wrong)

Swapping the two alternatives restores the MySQL precedence:

  1 OR 1 XOR 1  ->  1 OR (1 XOR 1)
  1 XOR 1 OR 1  ->  (1 XOR 1) OR 1

AND stays above both alternatives, so the AND/OR groupings are unchanged.
No visitor change is needed: MySQLStatementVisitor#visitExpr discriminates on
ctx.XOR() / ctx.andOperator() / ctx.orOperator(), which are mutually exclusive.

Covered by the Parser IT case select_where_with_expr_with_xor_or.

* Fix MySQL OR and XOR operator precedence

MySQL evaluates `AND` tighter than `XOR`, and `XOR` tighter than `OR`.
In ANTLR4 a directly left-recursive rule assigns precedence by the order
of its alternatives, so `expr` had to list `XOR` before `orOperator`.
It listed them the other way around, grouping `1 OR 1 XOR 1` as
`(1 OR 1) XOR 1`.

Apply the same reordering to the Doris grammar, which keeps its own copy
of this shared rule. Doris documents the same precedence (`AND, &&` = 9,
`XOR` = 10, `OR` = 11), so both dialects now match their vendors.

Cover both dialects with one Parser IT case; its expected AST carries no
`db-types`, so MySQL and Doris assert the same tree from the same SQL.

Reported in #40295. Reverting either grammar alone reproduces the
failures in the corresponding `Internal*ParserIT`.

Report URL: https://github.com/apache/shardingsphere/actions/runs/39784675751

With regards,
GitHub Actions via GitBox

Reply via email to