Commit 8dbfaa2a authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-28437: Assertion `!eliminated' failed in Item_subselect::exec

(This is the assert that was added in fix for MDEV-26047)

Table elimination may remove an ON expression from an outer join.
However SELECT_LEX::update_used_tables() will still call

  item->walk(&Item::eval_not_null_tables)

for eliminated expressions. If the subquery is constant and cheap
Item_cond_and will attempt to evaluate it, which will trigger an
assert.
The fix is not to call update_used_tables() or eval_not_null_tables()
for ON expressions that were eliminated.
parent ba4927e5
...@@ -661,3 +661,14 @@ group by (select a),(select 1) ...@@ -661,3 +661,14 @@ group by (select a),(select 1)
); );
1 1
drop table t1; drop table t1;
#
# MDEV-28437: Assertion `!eliminated' failed in Item_subselect::exec
#
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (3),(4);
SELECT 1 IN (SELECT a FROM t1 LEFT JOIN t2 ON (a = b AND EXISTS (SELECT * FROM t1)));
1 IN (SELECT a FROM t1 LEFT JOIN t2 ON (a = b AND EXISTS (SELECT * FROM t1)))
1
drop table t1,t2;
...@@ -655,3 +655,17 @@ select 1 from t1 where not exists ...@@ -655,3 +655,17 @@ select 1 from t1 where not exists
--enable_warnings --enable_warnings
drop table t1; drop table t1;
--echo #
--echo # MDEV-28437: Assertion `!eliminated' failed in Item_subselect::exec
--echo #
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (3),(4);
SELECT 1 IN (SELECT a FROM t1 LEFT JOIN t2 ON (a = b AND EXISTS (SELECT * FROM t1)));
drop table t1,t2;
# End of 10.2 tests
...@@ -4229,7 +4229,7 @@ void SELECT_LEX::update_used_tables() ...@@ -4229,7 +4229,7 @@ void SELECT_LEX::update_used_tables()
} }
} }
while ((embedding= embedding->embedding)); while ((embedding= embedding->embedding));
if (tl->on_expr) if (tl->on_expr && !is_eliminated_table(join->eliminated_tables, tl))
{ {
tl->on_expr->update_used_tables(); tl->on_expr->update_used_tables();
tl->on_expr->walk(&Item::eval_not_null_tables, 0, NULL); tl->on_expr->walk(&Item::eval_not_null_tables, 0, NULL);
...@@ -4253,8 +4253,11 @@ void SELECT_LEX::update_used_tables() ...@@ -4253,8 +4253,11 @@ void SELECT_LEX::update_used_tables()
if (embedding->on_expr && if (embedding->on_expr &&
embedding->nested_join->join_list.head() == tl) embedding->nested_join->join_list.head() == tl)
{ {
embedding->on_expr->update_used_tables(); if (!is_eliminated_table(join->eliminated_tables, embedding))
embedding->on_expr->walk(&Item::eval_not_null_tables, 0, NULL); {
embedding->on_expr->update_used_tables();
embedding->on_expr->walk(&Item::eval_not_null_tables, 0, NULL);
}
} }
tl= embedding; tl= embedding;
embedding= tl->embedding; embedding= tl->embedding;
......
...@@ -25495,7 +25495,7 @@ static void print_table_array(THD *thd, ...@@ -25495,7 +25495,7 @@ static void print_table_array(THD *thd,
too) too)
*/ */
static bool is_eliminated_table(table_map eliminated_tables, TABLE_LIST *tbl) bool is_eliminated_table(table_map eliminated_tables, TABLE_LIST *tbl)
{ {
return eliminated_tables && return eliminated_tables &&
((tbl->table && (tbl->table->map & eliminated_tables)) || ((tbl->table && (tbl->table->map & eliminated_tables)) ||
......
...@@ -2330,4 +2330,6 @@ int create_sort_index(THD *thd, JOIN *join, JOIN_TAB *tab, Filesort *fsort); ...@@ -2330,4 +2330,6 @@ int create_sort_index(THD *thd, JOIN *join, JOIN_TAB *tab, Filesort *fsort);
JOIN_TAB *first_explain_order_tab(JOIN* join); JOIN_TAB *first_explain_order_tab(JOIN* join);
JOIN_TAB *next_explain_order_tab(JOIN* join, JOIN_TAB* tab); JOIN_TAB *next_explain_order_tab(JOIN* join, JOIN_TAB* tab);
bool is_eliminated_table(table_map eliminated_tables, TABLE_LIST *tbl);
#endif /* SQL_SELECT_INCLUDED */ #endif /* SQL_SELECT_INCLUDED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment