Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 12.3.2
-
ubuntu22.04
Description
Summary (for Jira Summary field)
Wrong result: CHAR() on inner table of LEFT JOIN wrongly converts outer join to inner join
Description
CHAR(NULL) returns a non-NULL empty string (CHAR(NULL) IS NOT NULL is true).
Therefore a WHERE predicate such as CHAR(inner_col) IS NOT NULL or CHAR(inner_col) NOT LIKE '...' must not be treated as null-rejecting for an outer join.
How to repeat
CREATE TABLE t0 (vkey INT); |
CREATE TABLE t7 (vkey INT); |
INSERT INTO t0 VALUES (6); |
-- t7 empty → LEFT JOIN always NULL-extends
|
|
|
-- Wrong (empty): CHAR() on inner column treated as null-rejecting
|
SELECT COUNT(*) AS c_char |
FROM t0 LEFT JOIN t7 ON t0.vkey = t7.vkey |
WHERE CHAR(t7.vkey) NOT LIKE 'YVR'; |
-- Actual: 0
|
-- Expected: 1
|
|
|
-- Correct: same value via CASE → not_null_tables not propagated
|
SELECT COUNT(*) AS c_case |
FROM t0 LEFT JOIN t7 ON t0.vkey = t7.vkey |
WHERE CHAR(CASE WHEN FALSE THEN t7.vkey ELSE t7.vkey END) NOT LIKE 'YVR'; |
-- Actual: 1
|
-- Expected: 1
|
|
|
-- Semantics: CHAR(NULL) is not SQL NULL
|
SELECT CHAR(NULL) IS NOT NULL; -- 1 |
|
|
DROP TABLE t0, t7; |
Self-join form (same root cause):
CREATE TABLE t1 (a INT, b INT); |
INSERT INTO t1 VALUES (1,1),(2,3); |
|
|
SELECT COUNT(*) FROM t1 LEFT JOIN t1 t2 ON t1.a = t2.b |
WHERE CHAR(t2.b) IS NOT NULL; |
-- Actual: 1
|
-- Expected: 2
|
|
|
-- SELECT-list shows the NULL-extended row still satisfies the predicate:
|
SELECT t1.a, t2.b, CHAR(t2.b) IS NOT NULL AS p |
FROM t1 LEFT JOIN t1 t2 ON t1.a = t2.b; |
-- row (2, NULL, 1) is present here but missing from the WHERE query above
|
|
|
DROP TABLE t1; |
Observed on: 12.3.2-MariaDB
Actual result
- CHAR(t7.vkey) NOT LIKE 'YVR' → COUNT
= 0 - CHAR(t2.b) IS NOT NULL on self LEFT JOIN → COUNT
= 1
Expected result
- CHAR(t7.vkey) NOT LIKE 'YVR' → COUNT
= 1 - CHAR(t2.b) IS NOT NULL on self LEFT JOIN → COUNT
= 2 - CASE wrapper and bare CHAR(col) must agree
Attachments
Issue Links
- is duplicated by
-
MDEV-40864 MAKE_SET() on inner table of LEFT JOIN wrongly rejects NULL-complemented rows
-
- Closed
-