MDEV-38295, MDEV-38272 Sig11 in LEX::resolve_references_to_cte at sql/sql_cte.cc, mem leak#4486
Merged
mariadb-RexJohnston merged 2 commits intomainfrom Feb 1, 2026
Merged
Conversation
Member
Author
|
Hi @sanja-byelkin you've already reviewed the previous commit in this tree. I've squashed the 2 bugfixes together, maybe i should squash the already reviewed fix too? |
5fd31b1 to
1ef4d6b
Compare
Member
Author
|
We still have a memory leak executing st_select_lex::cleanup() is not called for select #2, so the underlying join structure isn't freed up. We are missing a call in Sql_cmd_dml::prepare()
before cleanup is called on the unit. |
fdf349a to
b24daf2
Compare
Member
Author
…ause CTE's are read only i.e It cannot have their columns updated in updates set clause. Attempting to do so , should throw error ERROR 1288 (HY000): The target table cte of the UPDATE is not updatable with cte as (select * from t1 where c < 5) update cte set cte.a =(select a from cte); Here, conversion from a single table to a multi table update bypasses the normal check by setting the TABLE_LIST object representing cte to be merge derived. This is incorrect, so we prohibit this conversion in TABLE_LIST::init_derived. Approved by: Sanja Byelkin (sanja@mariadb.com)
Lex::save_list contents remain from a previous query that has invalid syntax and isn't reset when processing a new query. We initialize this structure along with it's peer in LEX::start. MDEV-38295 Recursive CTE usage leaks memory when not used in a top level select During st_select_lex::cleanup() we assume that leaf tables and any associated recursive table references can only be present when a join structure is present. After MDEV-37220 this is no longer true. We shift our cleanup routine out of the test for a join. We add Multidelete_prelocking_strategy::handle_end() in the same manner as Multiupdate_prelocking_strategy::handle_end() (but with minimal processing as yet) to populate these leaf_tables in the outermost select when it is a delete statement. We add in a call to free_underlaid_joins() to the error processing section of Sql_cmd_dml::execute to free up temporary tables that were allocated in prepare, but not freed up when execute is bypassed because an error occured during prepare. Sergei Petrunia: Better comments for MDEV-38272, MDEV-38272 Approved by: Sergei Petrunia (sergey@mariadb.com)
b24daf2 to
56c22c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Bugs fixes related to testing MDEV-37220 Allow UPDATE/DELETE to read from a CTE
Release Notes
N/A
How can this PR be tested?
mtr main.cte_update_delete
If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.
Basing the PR against the correct MariaDB version
mainbranch.PR quality check