-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-37220 Allow UPDATE/DELETE to read from a CTE #4433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
39b5291 to
9a0958f
Compare
| description varchar(50) | ||
| ); | ||
|
|
||
| let $e= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use more descriptive names.
$empty_t3, $fill_t3 ?
|
Can't believe test coverage for this one is not present but I don't see it anywhere: create table t1 (a int, b int , c int);
insert into t1 select seq, seq, seq from seq_1_to_100;
with T as (select * from t1) delete from T where a<3;
ERROR 1288 (HY000): The target table T of the DELETE is not updatableOk... with T as (select * from t1) update T set a=3;
ERROR 1054 (42S22): Unknown column 'a' in 'SET'I'm not sure how we arrive at this error here. MariaDB [test]> with T as (select * from t1) update T set T.a=3;
ERROR 1054 (42S22): Unknown column 'T.a' in 'SET' |
MariaDB [test]> with T as (select * from t1) update T set T.a=3;
ERROR 1054 (42S22): Unknown column 'T.a' in 'SET'What is happening here is that because name resolution is performed on the field T.a at the end of Multiupdate_prelocking_strategy::handle_end() (it calls setup_fields), it is searching through the definition of T prior to setup_wild() being performed on the select_lex associated with the derived table. For a derived table, this limitation is caught in the parser. For a view, we do not store any wildcards in the definition. I'm currently looking for the simplest fix. |
|
The patch makes use of LEX::save_list. I was concerned what other users are there. LEX::save_list should get a comment: I'm also wondering if we could move save_list to somewhere where it's clear its lifetime is parser: and then make debug build wipe out lex->parser_state after parsing is finished... |
We extend from the SQL standard to match the functionality of other databases that allow the inclusion of a CTE definition prior to update and delete statements. These CTEs are currently read only, like other derived tables, so cannot have their columns updated in updates set clause, nor have rows removed in the delete statement.
9a0958f to
270a3e0
Compare
|
Description
We extend from the SQL standard to match the functionality of other databases allowing the inclusion of a CTE definition prior to update and delete statements. These CTEs are currently read only, like other derived tables, so cannot have their columns updated in updates set clause, nor have rows removed in the delete statement.
Release Notes
Allow CTE definitions prior to UPDATE and DELETE statements.
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