Skip to content

Commit 0eca91a

Browse files
committed
MDEV-30080 Wrong result with LEFT JOINs involving constant tables
The reason things fails in 10.5 and above is that test_quick_select() returns -1 (impossible range) for empty tables if there are any conditions attached. This didn't happen in 10.4 as the cost for a range was more than for a table scan with 0 rows and get_key_scan_params() did not create any range plans and thus did not mark the range as impossible. The code that checked the 'impossible range' conditions did not take into account all cases of LEFT JOIN usage. Adding an extra check if the table is used with an ON condition in case of 'impossible range' fixes the issue.
1 parent 3316a54 commit 0eca91a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

mysql-test/main/join.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,6 +3435,7 @@ SELECT COUNT(*) FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b = t3.c) ON t1.a = t2.
34353435
COUNT(*)
34363436
2
34373437
DROP TABLE t1, t2, t3;
3438+
# End of 10.5 tests
34383439
#
34393440
# MDEV-30256 Wrong result (missing rows) upon join with empty table
34403441
#

mysql-test/main/join.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,8 @@ SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b = t3.c) ON t1.a = t2.b;
18381838
SELECT COUNT(*) FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.b = t3.c) ON t1.a = t2.b;
18391839
DROP TABLE t1, t2, t3;
18401840

1841+
--echo # End of 10.5 tests
1842+
18411843
--echo #
18421844
--echo # MDEV-30256 Wrong result (missing rows) upon join with empty table
18431845
--echo #

0 commit comments

Comments
 (0)