Skip to content

MySQL dialect gives logical XOR the same tier as OR #2835

Closed

Description

@pbottine

Reproduction

At current master commit f6ac2571e6e9777d6a5ee942a4ea53cd91153e4d, compile and run this with the built JAR on the classpath:

import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.AbstractJSqlParser.Dialect;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.Select;
public class Repro {
  static void show(Expression e, String prefix) {
    System.out.println(prefix + e.getClass().getSimpleName() + ": " + e);
    if (e instanceof BinaryExpression b) {
      show(b.getLeftExpression(), prefix + "  L ");
      show(b.getRightExpression(), prefix + "  R ");
    }
  }
  public static void main(String[] args) throws Exception {
    for (String x : new String[]{"1 OR 1 XOR 1", "1 OR (1 XOR 1)"}) {
      Select s = (Select) CCJSqlParserUtil.parse("SELECT " + x + " AS x",
          p -> p.withDialect(Dialect.MYSQL));
      System.out.println("INPUT " + x);
      show(s.getPlainSelect().getSelectItem(0).getExpression(), "");
    }
  }
}

Observed on 2026-10-19: unparenthesized input has a XorExpression root with OrExpression(1, 1) on the left. The parenthesized control has an OrExpression root. MySQL puts logical XOR above OR, so the unparenthesized input should also have an OR root: 1 OR (1 XOR 1) evaluates to true, whereas (1 OR 1) XOR 1 evaluates to false.

The boolean parser loop comments that XOR should have precedence 3 and OR precedence 2, but assigns both the value 2. The resulting AST groups them left-to-right. #1070 concerns OR/AND; #2834 concerns a separate arithmetic/bitwise parser loop.

Activity

  1. added a commit that references this issue on Oct 22, 2026
    bfafeaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions