Skip to content

Conversation

@mariadb-RexJohnston
Copy link
Member

  • The Jira issue number for this PR is: MDEV-38295, MDEV-38272

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

  • 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.
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.
@mariadb-RexJohnston
Copy link
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?

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

Development

Successfully merging this pull request may close these issues.

3 participants