Skip to content

MDEV-39597: Remove save/restore of proc_info in free_tmp_table#5102

Open
ARaveala wants to merge 2 commits into
MariaDB:10.11from
ARaveala:MDEV-39597-duplicate-sending-data-10.11
Open

MDEV-39597: Remove save/restore of proc_info in free_tmp_table#5102
ARaveala wants to merge 2 commits into
MariaDB:10.11from
ARaveala:MDEV-39597-duplicate-sending-data-10.11

Conversation

@ARaveala
Copy link
Copy Markdown

This is a continuation of #5097, targeting 10.11 as requested by the reviewer.

MDEV-39597: Remove save/restore of proc_info in free_tmp_table

Problem
SHOW PROFILE reports duplicate stage entries for INSERT...SELECT queries. The duplicate appears immediately after "Removing tmp table" and is caused by a save/restore pattern in free_tmp_table that blindly restores the previous stage name on exit, regardless of whether that stage is still accurate.
The same pattern implicitly also caused a duplicate "Creating sort index" entry in GROUP BY with filesort queries.
Fix
Removed the save and restore of proc_info in free_tmp_table. The "Removing tmp table" stage now remains active until the caller sets the next stage.
Trade-off
"Removing tmp table" will now appear slightly longer in profiles as it remains active briefly after the function returns. This is considered less misleading than restoring an incorrect stage name.
Scope
free_tmp_table is called from multiple files. A broader audit of all call sites is out of scope for this fix:

grep -rn "free_tmp_table" sql/ --include="*.cc" -l

Further investigation
The same save/restore pattern appears in other locations in the codebase. I intend to investigate these separately, any guidance on what to prioritise or test would be welcome.

SHOW PROFILE results abbreviated:

Before (INSERT...SELECT)

| Sending data | 0.002404 |
| Removing tmp table | 0.000098 |
| Sending data | 0.000079 | ← duplicate
| End of update loop | 0.000074 |


After

| Sending data | 0.002482 |
| Removing tmp table | 0.000172 |
| End of update loop | 0.000077 |


Provided under the MariaDB Contributor Agreement (MCA)

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new test case to verify that profiling stages are not duplicated during INSERT...SELECT operations, specifically targeting the 'Removing tmp table' stage. However, the actual server-side implementation to fix the underlying issue is missing from the current diff. Feedback also suggests improving the test's robustness by avoiding hardcoded query IDs, fixing a typo in the test output, and expanding the test suite to cover GROUP BY scenarios with filesort.

Comment thread mysql-test/main/mdev-39597.test
Comment thread mysql-test/main/mdev-39597.test
Comment thread mysql-test/main/mdev-39597.test Outdated
INSERT INTO profile_test (name, value)
SELECT name, value FROM profile_test LIMIT 5;

--echo # Check that no stage appears twice consecutivley around removing tmp table
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a typo in the echo message: "consecutivley" should be "consecutively".

--echo # Check that no stage appears twice consecutively around removing tmp table

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread mysql-test/main/mdev-39597.test
@ARaveala ARaveala force-pushed the MDEV-39597-duplicate-sending-data-10.11 branch 2 times, most recently from 4e64d90 to 6c3b644 Compare May 21, 2026 08:21
@ARaveala
Copy link
Copy Markdown
Author

This is a continuation of #5097, targeting 10.11 as requested by @gkodinov. The previous PR was closed and reopened here to correct the base branch. All previous review comments have been addressed.

SHOW PROFILE reports duplicate stage entries for INSERT...SELECT
caused by a save/restore pattern in free_tmp_table that blindly
restores the previous stage name after tmp table removal.

The fix removes the save/restore. The 'Removing tmp table' stage
now remains active until the caller sets the next stage.

Test uses --disable_ps2_protocol following the pattern in
show_profile.test to ensure consistent QUERY_ID in PS protocol mode.

fixup: add trailing newline to test file
@ARaveala ARaveala force-pushed the MDEV-39597-duplicate-sending-data-10.11 branch from 6c3b644 to b317ede Compare May 21, 2026 08:54
@ARaveala
Copy link
Copy Markdown
Author

rpl.rpl_row_foreign_key_mdl passes locally in isolation. Likely a flaky replication test that fails under parallel load on the buildbot. Unrelated to this fix.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label May 21, 2026
@gkodinov gkodinov changed the title MDEV-39597: Remove save/restore of proc_info in free_tmp_table MDEV-39597: Remove save/restore of proc_info in free_tmp_table May 21, 2026
Copy link
Copy Markdown
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for your work so far!

Please stay tuned for the final review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants