diff --git a/mysql-test/main/mdev-39597.result b/mysql-test/main/mdev-39597.result new file mode 100644 index 0000000000000..92ba163050642 --- /dev/null +++ b/mysql-test/main/mdev-39597.result @@ -0,0 +1,31 @@ +# +# MDEV-39597: SHOW PROFILE reports duplicate sending data +# stage for INSERT...SELECT due to save/restore in free_tmp_table +# +CREATE TABLE profile_test ( +id INT PRIMARY KEY AUTO_INCREMENT, +name VARCHAR(100), +value INT +); +INSERT INTO profile_test (name, value) VALUES +('alpha',1),('beta',2),('gamma',3),('delta',4),('epsilon',5), +('zeta',6),('eta',7),('theta',8),('iota',9),('kappa',10); +SET profiling = 1; +INSERT INTO profile_test (name, value) +SELECT name, value FROM profile_test LIMIT 5; +# Check that no stage appears twice consecutively around removing tmp table +SELECT COUNT(*) AS duplicate_stage_found +FROM ( +SELECT +STATE, +LAG(STATE) OVER (ORDER BY SEQ) AS prev_status, +LEAD(STATE) OVER (ORDER BY SEQ) AS next_status +FROM information_schema.profiling +WHERE QUERY_ID = 1 +) t +WHERE STATE = 'Removing tmp table' +AND prev_status = next_status; +duplicate_stage_found +0 +SET profiling = 0; +DROP TABLE profile_test; diff --git a/mysql-test/main/mdev-39597.test b/mysql-test/main/mdev-39597.test new file mode 100644 index 0000000000000..62b8c5b38f2b4 --- /dev/null +++ b/mysql-test/main/mdev-39597.test @@ -0,0 +1,39 @@ +--echo # +--echo # MDEV-39597: SHOW PROFILE reports duplicate sending data +--echo # stage for INSERT...SELECT due to save/restore in free_tmp_table +--echo # + +--source include/have_profiling.inc +--disable_ps2_protocol + +CREATE TABLE profile_test ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(100), + value INT +); +INSERT INTO profile_test (name, value) VALUES + ('alpha',1),('beta',2),('gamma',3),('delta',4),('epsilon',5), + ('zeta',6),('eta',7),('theta',8),('iota',9),('kappa',10); +SET profiling = 1; +INSERT INTO profile_test (name, value) + SELECT name, value FROM profile_test LIMIT 5; + +--echo # Check that no stage appears twice consecutively around removing tmp table + +SELECT COUNT(*) AS duplicate_stage_found +FROM ( + SELECT + STATE, + LAG(STATE) OVER (ORDER BY SEQ) AS prev_status, + LEAD(STATE) OVER (ORDER BY SEQ) AS next_status + FROM information_schema.profiling + WHERE QUERY_ID = 1 +) t +WHERE STATE = 'Removing tmp table' +AND prev_status = next_status; + +--enable_ps2_protocol + +# clean up +SET profiling = 0; +DROP TABLE profile_test; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 70785f531bb00..90763725f8b8e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -22321,12 +22321,10 @@ void free_tmp_table(THD *thd, TABLE *entry) { MEM_ROOT own_root= entry->mem_root; - const char *save_proc_info; DBUG_ENTER("free_tmp_table"); DBUG_PRINT("enter",("table: %s alias: %s",entry->s->table_name.str, entry->alias.c_ptr())); - save_proc_info=thd->proc_info; THD_STAGE_INFO(thd, stage_removing_tmp_table); if (entry->file && entry->is_created()) @@ -22362,7 +22360,6 @@ free_tmp_table(THD *thd, TABLE *entry) } free_root(&own_root, MYF(0)); /* the table is allocated in its own root */ - thd_proc_info(thd, save_proc_info); DBUG_VOID_RETURN; }