diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result index ac14f891622..a564fd1045c 100644 --- a/mysql-test/r/bdb.result +++ b/mysql-test/r/bdb.result @@ -1289,6 +1289,25 @@ SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterd"); id 4 DROP TABLE t1; +create table t1 (a int, key(a)) engine=bdb; +create table t2 (b int, key(b)) engine=bdb; +insert into t1 values (1),(1),(2),(3),(4); +insert into t2 values (1),(5),(6),(7); +delete from t1 where (a in (select b from t2)); +select count(*) from t1; +count(*) +3 +insert into t1 set a=(select b from t2); +ERROR 21000: Subquery returns more than 1 row +select count(*) from t1; +count(*) +3 +update t1 set a = a + 1 where (a in (select b from t2)); +select count(*) from t1; +count(*) +3 +drop table t1, t2; +End of 4.1 tests create temporary table t1 (a int, primary key(a)) engine=bdb; select * from t1; a diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test index 72b3ee89ed5..d3068b29e28 100644 --- a/mysql-test/t/bdb.test +++ b/mysql-test/t/bdb.test @@ -938,7 +938,25 @@ SELECT id FROM t1 WHERE (list_id = 1) AND (term = "lettera"); SELECT id FROM t1 WHERE (list_id = 1) AND (term = "letterd"); DROP TABLE t1; -# End of 4.1 tests +# +# Bug #15536: Crash when DELETE with subquery using BDB tables +# +create table t1 (a int, key(a)) engine=bdb; +create table t2 (b int, key(b)) engine=bdb; +insert into t1 values (1),(1),(2),(3),(4); +insert into t2 values (1),(5),(6),(7); +delete from t1 where (a in (select b from t2)); +select count(*) from t1; +# INSERT also blows up +--error 1242 +insert into t1 set a=(select b from t2); +select count(*) from t1; +# UPDATE also blows up +update t1 set a = a + 1 where (a in (select b from t2)); +select count(*) from t1; +drop table t1, t2; + +--echo End of 4.1 tests # # alter temp table diff --git a/sql/share/charsets/latin5.xml b/sql/share/charsets/latin5.xml index 67e5873c503..5004f045889 100644 --- a/sql/share/charsets/latin5.xml +++ b/sql/share/charsets/latin5.xml @@ -112,11 +112,6 @@ - 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F @@ -130,10 +125,10 @@ 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB - CC CD CE CF D0 D1 D2 44 D3 D4 D5 D6 D7 D8 D9 DA - 49 DB DC DD DE DF 53 E0 E1 E2 E3 E4 5B 4C 58 E5 - CC CD CE CF D0 D1 D2 44 D3 D4 D5 D6 D7 D8 D9 DA - 49 DB DC DD DE DF 53 FA E1 E2 E3 E4 5B 4B 58 FF + 41 41 41 41 41 41 41 44 46 46 46 46 4C 4C 4C 4C + 49 51 52 52 52 52 53 E0 52 5A 5A 5A 5B 4C 58 57 + 41 41 41 41 41 41 41 44 46 46 46 46 4C 4C 4C 4C + 49 51 52 52 52 52 53 FA 52 5A 5A 5A 5B 4B 58 5F diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 92fc7e4bfd2..393e8184725 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -293,6 +293,7 @@ cleanup: if (!transactional_table) thd->options|=OPTION_STATUS_NO_TRANS_UPDATE; } + free_underlaid_joins(thd, select_lex); if (transactional_table) { if (ha_autocommit_or_rollback(thd,error >= 0)) @@ -304,7 +305,6 @@ cleanup: mysql_unlock_tables(thd, thd->lock); thd->lock=0; } - free_underlaid_joins(thd, select_lex); if (error < 0) { thd->row_count_func= deleted; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8903f28be11..e5ea296afab 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -257,7 +257,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, */ bool log_on= (thd->options & OPTION_BIN_LOG) || (!(thd->security_ctx->master_access & SUPER_ACL)); - bool transactional_table; + bool transactional_table, joins_freed= FALSE; uint value_count; ulong counter = 1; ulonglong id; @@ -513,6 +513,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, thd->row_count++; } + free_underlaid_joins(thd, &thd->lex->select_lex); + joins_freed= TRUE; + /* Now all rows are inserted. Time to update logs and sends response to user @@ -611,7 +614,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, thd->row_count_func= info.copied+info.deleted+info.updated; ::send_ok(thd, (ulong) thd->row_count_func, id, buff); } - free_underlaid_joins(thd, &thd->lex->select_lex); thd->abort_on_warning= 0; DBUG_RETURN(FALSE); @@ -620,7 +622,8 @@ abort: if (lock_type == TL_WRITE_DELAYED) end_delayed_insert(thd); #endif - free_underlaid_joins(thd, &thd->lex->select_lex); + if (!joins_freed) + free_underlaid_joins(thd, &thd->lex->select_lex); thd->abort_on_warning= 0; DBUG_RETURN(TRUE); } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 6ec895bacb1..a86d1b57190 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -527,6 +527,7 @@ int mysql_update(THD *thd, if (!transactional_table) thd->options|=OPTION_STATUS_NO_TRANS_UPDATE; } + free_underlaid_joins(thd, select_lex); if (transactional_table) { if (ha_autocommit_or_rollback(thd, error >= 0)) @@ -539,7 +540,6 @@ int mysql_update(THD *thd, thd->lock=0; } - free_underlaid_joins(thd, select_lex); if (error < 0) { char buff[STRING_BUFFER_USUAL_SIZE];