Commit 477629d2 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-21147 Assertion `marked_for_read()' upon UPDATE on versioned table via view

Unit prepare prematurely fixed field which must be fixed via
setup_conds() to correctly update table->covering_keys.

Call vers_setup_conds() directly instead, because actually everything
else is not needed.
parent cef2b34f
......@@ -295,5 +295,17 @@ primary key (pk)
create or replace view v1 as select * from t1;
insert into t1 values (1, null, 'd') , (2, null, 'i') ;
update v1 set a= null where b = '';
create or replace table t1 (id int, k int, primary key (id)) engine=innodb with system versioning;
insert into t1 values (1,1),(2,2);
create or replace view v1 as select * from t1;
update v1 set id= 2 where k = 0;
create or replace table t1 (a int) with system versioning;
create or replace view v1 as select * from t1;
create or replace procedure sp() update v1 set xx = 1;
call sp;
ERROR 42S22: Unknown column 'xx' in 'field list'
call sp;
ERROR 42S22: Unknown column 'xx' in 'field list'
drop procedure sp;
drop view v1;
drop table t1;
......@@ -214,7 +214,21 @@ create or replace view v1 as select * from t1;
insert into t1 values (1, null, 'd') , (2, null, 'i') ;
update v1 set a= null where b = '';
create or replace table t1 (id int, k int, primary key (id)) engine=innodb with system versioning;
insert into t1 values (1,1),(2,2);
create or replace view v1 as select * from t1;
update v1 set id= 2 where k = 0;
create or replace table t1 (a int) with system versioning;
create or replace view v1 as select * from t1;
create or replace procedure sp() update v1 set xx = 1;
--error ER_BAD_FIELD_ERROR
call sp;
--error ER_BAD_FIELD_ERROR
call sp;
# cleanup
drop procedure sp;
drop view v1;
drop table t1;
......
......@@ -707,8 +707,15 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
case SQLCOM_DELETE_MULTI:
case SQLCOM_UPDATE:
case SQLCOM_UPDATE_MULTI:
if ((res= unit->prepare(derived, derived->derived_result, 0)))
if ((res= first_select->vers_setup_conds(thd,
derived->merge_underlying_list)))
goto exit;
if (derived->merge_underlying_list->where)
{
Query_arena_stmt on_stmt_arena(thd);
derived->where= and_items(thd, derived->where,
derived->merge_underlying_list->where);
}
default:
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment