Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
12.2.2
-
None
-
Ubuntu 20.04
-
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.