Skip to content

Conversation

@mariadb-RexJohnston
Copy link
Member

  • The Jira issue number for this PR is: MDEV-38258

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

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants