Bug #120589 Writing a RIGHT JOIN result into a temp table loses an obvious IFNULL match
Submitted: 1 Jun 14:12 Modified: 1 Jun 19:51
Reporter: y x Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:9.7.0 OS:Ubuntu
Assigned to: CPU Architecture:x86

[1 Jun 14:12] y x
Description:
`t2` is empty, so `t2 RIGHT JOIN t0 ON FALSE` must preserve the row `t0.c0 = 0` as a null-extended row with `t2.c0 = NULL`. Therefore `IFNULL(t2.c0, t0.c0)` must be `0`, and the downstream `INNER JOIN t1 ON ... >= t1.c0` must keep exactly the row `t1.c0 = 0`. MySQL returns that row on both the direct `SELECT` and an equivalent derived-table wrapper, but loses it when the same result is written into a temporary table via `CREATE TEMPORARY TABLE ... AS SELECT`.

How to repeat:
CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT);
CREATE TABLE t2(c0 DECIMAL(10,0));

INSERT INTO t0 VALUES (0), (NULL);
INSERT INTO t1 VALUES (0), (1);

SELECT t1.c0 AS ref0
FROM t2 RIGHT JOIN t0 ON FALSE
INNER JOIN t1 ON IFNULL(t2.c0, t0.c0) >= t1.c0
WHERE t0.c0 IS NOT NULL;

DROP TEMPORARY TABLE IF EXISTS temp_0;
CREATE TEMPORARY TABLE temp_0 AS
SELECT t1.c0 AS t1_c0, t0.c0 AS t0_c0
FROM t2 RIGHT JOIN t0 ON FALSE
INNER JOIN t1 ON IFNULL(t2.c0, t0.c0) >= t1.c0;

SELECT t1_c0 AS ref0
FROM temp_0
WHERE t0_c0 IS NOT NULL; -- Expected correct result: both SELECTs should return 0  -- actual Wrong result: direct SELECT returns 0, temp-table readback returns <empty>
[1 Jun 19:51] Roy Lyseng
Thank you for the bug report.

Verified as a duplicate of bug#120429.

A fix for this problem will be delivered in release 9.7.1.