From 27b762e23d8305bbc65dc61d283fe192e2dbd00a Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 29 Oct 2020 12:14:19 +0300 Subject: [PATCH] MDEV-22805 SIGSEGV in check_fields on UPDATE Additional case for PS protocol: UPDATE is converted to multi-update in mysql_multi_update_prepare(). --- mysql-test/suite/period/r/update.result | 3 +++ mysql-test/suite/period/t/update.test | 6 +++++- sql/sql_update.cc | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/period/r/update.result b/mysql-test/suite/period/r/update.result index b61d8a73b83..f726b4c07cf 100644 --- a/mysql-test/suite/period/r/update.result +++ b/mysql-test/suite/period/r/update.result @@ -299,6 +299,9 @@ CREATE TABLE t1 (a INT, b DATE, c DATE, PERIOD FOR APPTIME(b, c)); INSERT INTO t1 VALUES(1, '1999-01-01', '2018-12-12'); UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; ERROR 42000: This version of MariaDB doesn't yet support 'updating and querying the same temporal periods table' +set @tmp= "UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100"; +execute immediate @tmp; +ERROR 42000: This version of MariaDB doesn't yet support 'updating and querying the same temporal periods table' CREATE VIEW v1 AS SELECT * FROM t1; UPDATE v1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; ERROR 42S02: 'v1' is a view diff --git a/mysql-test/suite/period/t/update.test b/mysql-test/suite/period/t/update.test index 66d3bc1e9bf..3f4dd2bdc68 100644 --- a/mysql-test/suite/period/t/update.test +++ b/mysql-test/suite/period/t/update.test @@ -192,8 +192,12 @@ CREATE TABLE t1 (a INT, b DATE, c DATE, PERIOD FOR APPTIME(b, c)); INSERT INTO t1 VALUES(1, '1999-01-01', '2018-12-12'); # Without a patch the following statement crashs a server built in debug mode +let $stmt= UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; --error ER_NOT_SUPPORTED_YET -UPDATE t1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; +eval $stmt; +eval set @tmp= "$stmt"; +--error ER_NOT_SUPPORTED_YET +execute immediate @tmp; CREATE VIEW v1 AS SELECT * FROM t1; --error ER_IT_IS_A_VIEW diff --git a/sql/sql_update.cc b/sql/sql_update.cc index c687b6ca2f5..9514b193407 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -190,6 +190,13 @@ static bool check_fields(THD *thd, TABLE_LIST *table, List &items, my_error(ER_IT_IS_A_VIEW, MYF(0), table->table_name.str); return TRUE; } + if (thd->lex->sql_command == SQLCOM_UPDATE_MULTI) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "updating and querying the same temporal periods table"); + + return true; + } DBUG_ASSERT(thd->lex->sql_command == SQLCOM_UPDATE); for (List_iterator_fast it(items); (item=it++);) {