Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 12.2.2
-
12.2.2-MariaDB-ubu2404
Description
Description:
A logical query divergence occurs when evaluating a non-zero division expression (BIT / DATE) in a boolean context dynamically versus evaluating it against a materialized column created via CREATE TABLE ... AS SELECT (CTAS).
In base table t0, c0 / c1 (1 / '2093-11-13') evaluates to a non-zero float value (~4.77e-8). When used in a boolean context inside WHERE clause (e.g., WHERE c0/c1), it evaluates to TRUE because the underlying value is non-zero (despite output formatting rendering it as 0.0000).
However, when executing CREATE TABLE t1 AS SELECT (c0/c1) AS c0 FROM t0;, CTAS materializes the column with a truncated fixed scale (e.g., DECIMAL(14,4) storing 0.0000). Consequently, in t1, WHERE c0 evaluates 0.0000 to FALSE in boolean context, yielding Empty set.
How to repeat:
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
– Step 1: Create base table t0 with BIT and DATE columns
CREATE TABLE t0 (c0 BIT, c1 DATE);
– Step 2: Insert values where c0/c1 results in a tiny positive float (~4.77e-8)
INSERT INTO t0 (c0, c1) VALUES (1, '2093-11-13');
– Step 3: Materialize expression into table t1 via CTAS
CREATE TABLE t1 AS SELECT (c0/c1) AS c0 FROM t0;
– Query 1: Dynamic evaluation on base table t0
– High-precision float is non-zero -> boolean TRUE
SELECT (c0/c1) FROM t0 WHERE (((c0/c1) OR (c0/c1)) AND ((c0/c1) = (c0/c1)));
– Returns: 1 row ('0.0000')
– Query 2: Evaluation on materialized table t1
– Materialized truncated decimal (0.0000) -> boolean FALSE
SELECT (c0) FROM t1 WHERE (((c0) OR (c0)) AND ((c0) = (c0)));
– Returns: Empty set (0 rows)
Attachments
Issue Links
- relates to
-
MDEV-6853 Unexpected zero result on 1 % <very small decimal> (wrong default precision of the returned result?)
-
- Confirmed
-