Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions mysql-test/main/mdev-39597.result
Original file line number Diff line number Diff line change
@@ -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;
39 changes: 39 additions & 0 deletions mysql-test/main/mdev-39597.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--echo #
Comment thread
gkodinov marked this conversation as resolved.
--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;
Comment thread
gkodinov marked this conversation as resolved.

--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
Comment thread
gkodinov marked this conversation as resolved.
) t
WHERE STATE = 'Removing tmp table'
AND prev_status = next_status;

--enable_ps2_protocol

# clean up
SET profiling = 0;
DROP TABLE profile_test;
3 changes: 0 additions & 3 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
Expand Down