Skip to content

Commit

Permalink
MDEV-21147 Assertion `marked_for_read()' upon UPDATE on versioned tab…
Browse files Browse the repository at this point in the history
…le 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.
  • Loading branch information
midenok committed Dec 4, 2019
1 parent cef2b34 commit 477629d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions mysql-test/suite/versioning/r/update.result
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions mysql-test/suite/versioning/t/update.test
Expand Up @@ -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;

Expand Down
9 changes: 8 additions & 1 deletion sql/sql_derived.cc
Expand Up @@ -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;
}
Expand Down

0 comments on commit 477629d

Please sign in to comment.