mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Fix bug#11868 NOT NULL ref optimization in subquery used in update must be
disabled if ref is built with a key from the updated table Problem was in add_not_null_conds() optimization function. It contains following code: JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; ... add_cond_and_fix(&referred_tab->select_cond, notnull); For UPDATE described in bug report referred_tab is 0 and dereferencing it crashes the server. sql/sql_select.cc: Fix bug #11868 NOT NULL ref optimization in subquery used in update must be disabled if ref is built with a key from the updated table mysql-test/r/update.result: Test case for bug#11868 Update with subquery with ref built with a key from the updated table crashes server. mysql-test/t/update.test: Test case for bug#11868 Update with subquery with ref built with a key from the updated table crashes server
This commit is contained in:
@@ -3555,7 +3555,12 @@ static void add_not_null_conds(JOIN *join)
|
||||
DBUG_ASSERT(item->type() == Item::FIELD_ITEM);
|
||||
Item_field *not_null_item= (Item_field*)item;
|
||||
JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab;
|
||||
if (referred_tab->join != join)
|
||||
/*
|
||||
For UPDATE queries such as:
|
||||
UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
|
||||
not_null_item is the t1.f1, but it's referred_tab is 0.
|
||||
*/
|
||||
if (!referred_tab || referred_tab->join != join)
|
||||
continue;
|
||||
Item *notnull;
|
||||
if (!(notnull= new Item_func_isnotnull(not_null_item)))
|
||||
|
||||
Reference in New Issue
Block a user