From 97ae1682f185be05276b172919e47fd86e9fd953 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Sat, 12 May 2012 11:53:14 +0400 Subject: [PATCH] BUG#997747: Assertion `join->best_read < ((double)1.79..5e+308L)' failed in greedy_search with LEFT JOINs and unique keys - Backport the fix for BUG#806524 from MariaDB 5.3 --- mysql-test/r/table_elim.result | 21 +++++++++++++++++++++ mysql-test/t/table_elim.test | 22 ++++++++++++++++++++++ sql/sql_select.cc | 8 +++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/table_elim.result b/mysql-test/r/table_elim.result index 6c713946b27..cd7d3cb6973 100644 --- a/mysql-test/r/table_elim.result +++ b/mysql-test/r/table_elim.result @@ -566,3 +566,24 @@ id select_type table type possible_keys key key_len ref rows Extra # ^^ The above must not produce a QEP of t3,t5,t2,t4 # as that violates the "no interleaving of outer join nests" rule. DROP TABLE t1,t2,t3,t4,t5; +# +# BUG#997747: Assertion `join->best_read < ((double)1.79..5e+308L)' +# failed in greedy_search with LEFT JOINs and unique keys +# +CREATE TABLE t1 (a1 INT); +CREATE TABLE t2 (b1 INT); +CREATE TABLE t3 (c1 INT, UNIQUE KEY(c1)); +CREATE TABLE t4 (d1 INT, UNIQUE KEY(d1)); +CREATE TABLE t5 (e1 INT); +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (2),(3); +INSERT INTO t3 VALUES (3),(4); +INSERT INTO t4 VALUES (4),(5); +INSERT INTO t5 VALUES (5),(6); +SELECT a1 FROM t1 LEFT JOIN t2 LEFT JOIN t3 LEFT JOIN t4 +ON c1 = d1 ON d1 = b1 ON a1 = b1 +LEFT JOIN t5 ON a1 = e1 ; +a1 +1 +2 +DROP TABLE t1,t2,t3,t4,t5; diff --git a/mysql-test/t/table_elim.test b/mysql-test/t/table_elim.test index 5576362b396..f5a90efe9a3 100644 --- a/mysql-test/t/table_elim.test +++ b/mysql-test/t/table_elim.test @@ -499,3 +499,25 @@ WHERE t3.f2 ; DROP TABLE t1,t2,t3,t4,t5; +--echo # +--echo # BUG#997747: Assertion `join->best_read < ((double)1.79..5e+308L)' +--echo # failed in greedy_search with LEFT JOINs and unique keys +--echo # +CREATE TABLE t1 (a1 INT); +CREATE TABLE t2 (b1 INT); +CREATE TABLE t3 (c1 INT, UNIQUE KEY(c1)); +CREATE TABLE t4 (d1 INT, UNIQUE KEY(d1)); +CREATE TABLE t5 (e1 INT); + +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (2),(3); +INSERT INTO t3 VALUES (3),(4); +INSERT INTO t4 VALUES (4),(5); +INSERT INTO t5 VALUES (5),(6); + +SELECT a1 FROM t1 LEFT JOIN t2 LEFT JOIN t3 LEFT JOIN t4 +ON c1 = d1 ON d1 = b1 ON a1 = b1 +LEFT JOIN t5 ON a1 = e1 ; + +DROP TABLE t1,t2,t3,t4,t5; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5fc6a8e9f8d..932fdf1b2cf 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9130,14 +9130,16 @@ static uint reset_nj_counters(JOIN *join, List *join_list) while ((table= li++)) { NESTED_JOIN *nested_join; + bool is_eliminated_nest= FALSE; if ((nested_join= table->nested_join)) { nested_join->counter= 0; - //nested_join->n_tables= my_count_bits(nested_join->used_tables & - // ~join->eliminated_tables); nested_join->n_tables= reset_nj_counters(join, &nested_join->join_list); + if (!nested_join->n_tables) + is_eliminated_nest= TRUE; } - if (!table->table || (table->table->map & ~join->eliminated_tables)) + if ((table->nested_join && !is_eliminated_nest) || + (!table->nested_join && (table->table->map & ~join->eliminated_tables))) n++; } DBUG_RETURN(n);