diff --git a/mysql-test/r/analyze_stmt_orderby.result b/mysql-test/r/analyze_stmt_orderby.result index 91f033ac3b9..d2abc1db163 100644 --- a/mysql-test/r/analyze_stmt_orderby.result +++ b/mysql-test/r/analyze_stmt_orderby.result @@ -364,3 +364,20 @@ ANALYZE } drop table t2; drop table t0, t1; +# +# MDEV-8282: crash in filesort() with simple ordered delete +# +create table t1(a int) engine=innodb; +delete from t1 order by a; +# EXPLAIN thinks it will use delete_all_rows(): +explain +delete from t1 order by a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 1 Deleting all rows +# ANALYZE shows that delete_all_rows() didn't work and we deleted rows +# one-by-one: +analyze +delete from t1 order by a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 0.00 100.00 100.00 Using filesort +drop table t1; diff --git a/mysql-test/t/analyze_stmt_orderby.test b/mysql-test/t/analyze_stmt_orderby.test index 965271ceded..1a89091aa32 100644 --- a/mysql-test/t/analyze_stmt_orderby.test +++ b/mysql-test/t/analyze_stmt_orderby.test @@ -1,4 +1,6 @@ +--source include/have_innodb.inc + create table t0(a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); @@ -91,3 +93,20 @@ select MAX(b) from t2 where mod(a,2)=0 group by c; drop table t2; drop table t0, t1; +--echo # +--echo # MDEV-8282: crash in filesort() with simple ordered delete +--echo # +create table t1(a int) engine=innodb; +delete from t1 order by a; + +--echo # EXPLAIN thinks it will use delete_all_rows(): +explain +delete from t1 order by a; + +--echo # ANALYZE shows that delete_all_rows() didn't work and we deleted rows +--echo # one-by-one: +analyze +delete from t1 order by a; + +drop table t1; + diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index e3610a8f919..ac4aa40d55b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -370,6 +370,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, goto cleanup; } /* Handler didn't support fast delete; Delete rows one by one */ + query_plan.cancel_delete_all_rows(); } if (conds) { diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 20b156a36b6..76424f60c34 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2372,6 +2372,10 @@ public: deleting_all_rows= true; scanned_rows= rows_arg; } + void cancel_delete_all_rows() + { + deleting_all_rows= false; + } Explain_delete* save_explain_delete_data(MEM_ROOT *mem_root, THD *thd); };