summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/versioning/r/sysvars.result29
-rw-r--r--mysql-test/suite/versioning/t/sysvars.test24
-rw-r--r--sql/sql_select.cc5
3 files changed, 57 insertions, 1 deletions
diff --git a/mysql-test/suite/versioning/r/sysvars.result b/mysql-test/suite/versioning/r/sysvars.result
index 9cb4911b321..cd858d6cf69 100644
--- a/mysql-test/suite/versioning/r/sysvars.result
+++ b/mysql-test/suite/versioning/r/sysvars.result
@@ -146,3 +146,32 @@ show status like "Feature_system_versioning";
Variable_name Value
Feature_system_versioning 2
drop table t;
+#
+# MDEV-22906 Disallow system_versioning_asof in DML
+#
+create or replace table t1 (x int) with system versioning;
+create or replace table t2 (y int);
+insert into t1 values (1);
+insert into t2 values (1);
+set system_versioning_asof= '1970-01-01 00:00:00';
+delete t1, t2 from t1 join t2 where t1.x = t2.y;
+select * from t1 for system_time as of timestamp now(6);
+x
+insert into t1 values (1);
+insert into t2 values (1);
+update t1, t2 set x= 2, y= 2 where x = y;
+select * from t1 for system_time as of timestamp now(6);
+x
+2
+replace t2 select x + 1 from t1;
+select * from t2;
+y
+2
+3
+insert t2 select x + 2 from t1;
+select * from t2;
+y
+2
+3
+4
+drop tables t1, t2;
diff --git a/mysql-test/suite/versioning/t/sysvars.test b/mysql-test/suite/versioning/t/sysvars.test
index 1999ddd13fc..2f62262fc8e 100644
--- a/mysql-test/suite/versioning/t/sysvars.test
+++ b/mysql-test/suite/versioning/t/sysvars.test
@@ -103,3 +103,27 @@ select * from t for system_time between '1970-01-01 00:00' and current_timestamp
show status like "Feature_system_versioning";
drop table t;
+
+--echo #
+--echo # MDEV-22906 Disallow system_versioning_asof in DML
+--echo #
+create or replace table t1 (x int) with system versioning;
+create or replace table t2 (y int);
+insert into t1 values (1);
+insert into t2 values (1);
+set system_versioning_asof= '1970-01-01 00:00:00';
+delete t1, t2 from t1 join t2 where t1.x = t2.y;
+select * from t1 for system_time as of timestamp now(6);
+
+insert into t1 values (1);
+insert into t2 values (1);
+update t1, t2 set x= 2, y= 2 where x = y;
+select * from t1 for system_time as of timestamp now(6);
+
+replace t2 select x + 1 from t1;
+select * from t2;
+
+insert t2 select x + 2 from t1;
+select * from t2;
+
+drop tables t1, t2;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 05da4a1e750..1f35754a8fe 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -778,9 +778,12 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
}
bool is_select= false;
+ bool use_sysvar= false;
switch (thd->lex->sql_command)
{
case SQLCOM_SELECT:
+ use_sysvar= true;
+ /* fall through */
case SQLCOM_INSERT_SELECT:
case SQLCOM_REPLACE_SELECT:
case SQLCOM_DELETE_MULTI:
@@ -824,7 +827,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
}
// propagate system_time from sysvar
- if (!vers_conditions.is_set() && is_select)
+ if (!vers_conditions.is_set() && use_sysvar)
{
if (vers_conditions.init_from_sysvar(thd))
DBUG_RETURN(-1);