diff --git a/mysql-test/suite/period/r/update.result b/mysql-test/suite/period/r/update.result index b02c075560e..b61d8a73b83 100644 --- a/mysql-test/suite/period/r/update.result +++ b/mysql-test/suite/period/r/update.result @@ -292,3 +292,15 @@ Warning 1264 Out of range value for column 'id' at row 1 Warning 1264 Out of range value for column 'id' at row 2 update ignore t1 for portion of p from '1995-07-06' to '2009-01-12' set f = 1; drop table t1; +# +# MDEV-22805 SIGSEGV in check_fields on UPDATE (optimized builds) | Assertion `thd->lex->sql_command == SQLCOM_UPDATE' failed. +# +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' +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 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/suite/period/t/update.test b/mysql-test/suite/period/t/update.test index d4a2080ea0a..66d3bc1e9bf 100644 --- a/mysql-test/suite/period/t/update.test +++ b/mysql-test/suite/period/t/update.test @@ -183,3 +183,21 @@ update ignore t1 set id = 2429681664; update ignore t1 for portion of p from '1995-07-06' to '2009-01-12' set f = 1; drop table t1; + +--echo # +--echo # MDEV-22805 SIGSEGV in check_fields on UPDATE (optimized builds) | Assertion `thd->lex->sql_command == SQLCOM_UPDATE' failed. +--echo # +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 +--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; + +CREATE VIEW v1 AS SELECT * FROM t1; +--error ER_IT_IS_A_VIEW +UPDATE v1 FOR PORTION OF APPTIME FROM (SELECT '1999-01-01' FROM t1 WHERE a=2) TO '2018-01-01' SET a = 100; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7504863f394..e8c94c6b363 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4373,6 +4373,11 @@ mysql_execute_command(THD *thd) /* mysql_update return 2 if we need to switch to multi-update */ if (up_result != 2) break; + if (thd->lex->period_conditions.is_set()) + { + DBUG_ASSERT(0); // Should never happen + goto error; + } } /* fall through */ case SQLCOM_UPDATE_MULTI: diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 31a015dd0e2..c687b6ca2f5 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -420,6 +420,14 @@ int mysql_update(THD *thd, DBUG_PRINT("info", ("Switch to multi-update")); /* pass counter value */ thd->lex->table_count= table_count; + if (thd->lex->period_conditions.is_set()) + { + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "updating and querying the same temporal periods table"); + + DBUG_RETURN(1); + } + /* convert to multiupdate */ DBUG_RETURN(2); }