Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40593

XOR with fractional DECIMAL operand: both XOR and NOT(XOR) return 1

    XMLWordPrintable

Details

    • Not for Release Notes

    Description

      Summary

      XOR with fractional DECIMAL operand: both XOR and NOT(XOR) return 1

      How to repeat

      SELECT (-0.01) XOR 1 AS xor_result,
             NOT ((-0.01) XOR 1) AS not_xor;
      

      Actual result on 12.2.2-MariaDB-ubu2404:

      +------------+----------+
      | xor_result | not_xor  |
      +------------+----------+
      |          1 |        1 |
      +------------+----------+
      

      Expected: xor_result = 0, not_xor = 1 (verified on MySQL 9.6.0).
      Per MariaDB documentation, XOR "evaluates to 1 if an odd number of
      operands is nonzero" — both -0.01 and 1 are nonzero, so the result
      must be 0.

      Also reproducible with runtime values, so it is not limited to
      constant folding:

      CREATE TABLE t(d DECIMAL(10,2));
      INSERT INTO t VALUES (-0.01);
      SELECT d XOR 1 AS x, NOT (d XOR 1) AS nx FROM t;
      DROP TABLE t;
      

      Pure integer operands and zero-valued DECIMALs behave correctly.

      Analysis

      Regardless of how a fractional DECIMAL is coerced to boolean,
      NOT must invert the value of its operand. Returning xor_result = 1
      and not_xor = 1 simultaneously is internally inconsistent.
      The misbehavior appears specific to fractional DECIMAL operands
      (e.g. -0.01 XOR '1' with a string literal reproduces as well).

      Environment

      MariaDB 12.2.2-MariaDB-ubu2404 (official Docker image), x86_64,
      default configuration.

      Attachments

        Activity

          People

            Unassigned Unassigned
            kocoli Ruixue Li
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.