Rainmemery opened a new pull request, #40329: URL: https://github.com/apache/shardingsphere/pull/40329
Fixes #40295. ## What changed `parser/sql/engine/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4`: moved the `expr XOR expr` alternative ahead of `expr orOperator expr` in the `expr` rule. ## Why MySQL's operator precedence table puts `XOR` above `OR` (`AND` > `XOR` > `OR`, see [MySQL 8.4 operator precedence](https://dev.mysql.com/doc/refman/8.4/en/operator-precedence.html)). In ANTLR4 the alternatives of a directly left-recursive rule are resolved by their order — the alternative listed earlier binds tighter — and the MySQL grammar listed `orOperator` before `XOR`, so `OR` outranked `XOR`. | SQL | before | after | MySQL | | --- | --- | --- | --- | | `1 OR 1 XOR 1` | `(1 OR 1) XOR 1` | `1 OR (1 XOR 1)` | `1 OR (1 XOR 1)` | | `1 XOR 1 OR 1` | `1 XOR (1 OR 1)` | `(1 XOR 1) OR 1` | `(1 XOR 1) OR 1` | | `1 OR 1 AND 1` | `1 OR (1 AND 1)` | `1 OR (1 AND 1)` | unchanged | | `1 AND 1 OR 1` | `(1 AND 1) OR 1` | `(1 AND 1) OR 1` | unchanged | `AND` keeps its position above both alternatives, so the two `AND`/`OR` groupings above are unaffected. The SQL Federation node derives its grouping from the parser AST, so it follows the fix. No visitor change is needed: `MySQLStatementVisitor#visitExpr` discriminates on `ctx.XOR()` / `ctx.andOperator()` / `ctx.orOperator()`, which are mutually exclusive in a given context. ## How it is checked - New Parser IT case `select_where_with_expr_with_xor_or` (`... WHERE t_order.order_id = ? XOR ? = t_order.order_id OR ? = t_order.order_id`), asserting the `XOR` node is nested inside the `OR` node. Per the testing rules, `StatementVisitor` behavior goes to Parser IT rather than a unit test. - **Ablation**: with only the grammar change reverted, that case fails with 2 errors (the `MySQL` and `H2` parameterizations); with the change applied it passes. - `mvn -pl test/it/parser test -Dtest='Internal*ParserIT'` → **11581 tests, 0 failures, 0 errors** (MySQL 1943, and no other dialect regressed). - `mvn -pl kernel/sql-federation/compiler test` → **323 tests, 0 failures** (the SQL Federation converter is the consumer that reads this AST). - `spotless:check` + `checkstyle:check` on both owning modules → 0 violations. ## AI-assisted contribution disclosure Material AI assistance (an AI coding agent: Codex, driven through the WorkBuddy desktop agent) was used to investigate the root cause and to draft this description. Affected files: - `parser/sql/engine/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4` - `test/it/parser/src/main/resources/sql/supported/dml/select-expression.xml` - `test/it/parser/src/main/resources/case/dml/select-expression.xml` Every change above was reviewed, built and verified locally by the human contributor, who accepts full responsibility for it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
