MDEV-38258 No error thrown when CTE columns updated in updates set clause#4473
Closed
mariadb-RexJohnston wants to merge 1 commit intomainfrom
Closed
MDEV-38258 No error thrown when CTE columns updated in updates set clause#4473mariadb-RexJohnston wants to merge 1 commit intomainfrom
mariadb-RexJohnston wants to merge 1 commit intomainfrom
Conversation
…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.
caa6f70 to
7fde72d
Compare
Member
|
Approved by Sanja, will get in together with a comment. |
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
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