MDEV-38258 No error thrown when CTE columns updated in updates set clause #4473
+43
−0
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
This query
WITH cte AS ( SELECT a from t1 ) update cte set cte.a=(select a from cte);
is converted from a single table update to multi-table, bypassing the normal check.
In the conversion, the TABLE_LIST representing cte is flagged as to be merged in TABLE_LIST::init_derived
As table cte is flagged as mergeable, it is NOT populated in first_select_lex()->leaf_tables, so isn't included in the check in
Multiupdate_prelocking_strategy::handle_end() that ensures we aren't trying to update our CTE.
Setting merged in TABLE_LIST::init_derived() is incorrect, cte SHOULD NOT be flagged as mergeable as it is the table to be updated.
Release Notes
Single to multitable conversion fix for using CTE in update statement.
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