Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mysql-test/main/cte_update_delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -1325,5 +1325,23 @@ insert into t3 values (1, 1, 'iron'),(2,2,'wood'),(0,NULL, 'gold'),
(3, 3, 'silver'), (4, 4, 'lead'), (5, 5, 'tin'), (6, 6, 'platinum'),
(7, 7, 'aluminium');
drop prepare s;
#
# MDEV-38258 No error thrown when CTE columns updated in updates set clause
#
with cte as (select * from t1 where c < 1)
update cte set cte.a =(select a from cte);
ERROR HY000: The target table cte of the UPDATE is not updatable
with cte as (select a from t1)
update cte set cte.a=(select a from cte limit 1);
ERROR HY000: The target table cte of the UPDATE is not updatable
with cte as (select a from t1),
cte2 as (select a from t3)
update t2, cte set cte.a=(select a from cte limit 1);
ERROR HY000: The target table cte of the UPDATE is not updatable
with cte as (select a from t1),
cte2 as (select a from t3)
update cte
set cte.a=(select a from cte where cte.a in (select a from cte2) limit 1);
ERROR HY000: The target table cte of the UPDATE is not updatable
drop table t1, t2, t3, t4, t5;
# End of 12.2 tests
22 changes: 22 additions & 0 deletions mysql-test/main/cte_update_delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,28 @@ eval $empty_t3;
eval $fill_t3;
drop prepare s;

--echo #
--echo # MDEV-38258 No error thrown when CTE columns updated in updates set clause
--echo #

--error ER_NON_UPDATABLE_TABLE
with cte as (select * from t1 where c < 1)
update cte set cte.a =(select a from cte);

--error ER_NON_UPDATABLE_TABLE
with cte as (select a from t1)
update cte set cte.a=(select a from cte limit 1);

--error ER_NON_UPDATABLE_TABLE
with cte as (select a from t1),
cte2 as (select a from t3)
update t2, cte set cte.a=(select a from cte limit 1);

--error ER_NON_UPDATABLE_TABLE
with cte as (select a from t1),
cte2 as (select a from t3)
update cte
set cte.a=(select a from cte where cte.a in (select a from cte2) limit 1);

drop table t1, t2, t3, t4, t5;

Expand Down
3 changes: 3 additions & 0 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10163,6 +10163,9 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view)
belong_to_view ? belong_to_view->updating :
!unit->outer_select()->outer_select();

if (with && updating)
set_materialized_derived();

/*
In the case where a table merge operation moves a derived table from
one select to another, table hints may be adjusted already.
Expand Down
Loading