Skip to content

Commit 329301d

Browse files
committed
MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table
The code in vers_select_conds_t::init_from_sysvar() assumed that the value of the system_versioning_asof is DATETIME. But it also could be DATE after a query like this: SET system_versioning_asof = DATE(NOW()); Fixing Sys_var_vers_asof::update() to convert the value of the assignment source to DATETIME if it returned DATE. Now vers_select_conds_t::init_from_sysvar() always gets a DATETIME value.
1 parent 056766c commit 329301d

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

mysql-test/suite/versioning/r/sysvars.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,13 @@ SELECT @@global.system_versioning_asof;
186186
@@global.system_versioning_asof
187187
2002-01-01 00:00:00.000000
188188
SET @@global.system_versioning_asof= DEFAULT;
189+
#
190+
# MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table
191+
#
192+
CREATE TABLE t1 (a INT) WITH SYSTEM VERSIONING;
193+
SET system_versioning_asof= DATE(NOW());
194+
SELECT * FROM t1;
195+
a
196+
DROP TABLE t1;
197+
SET system_versioning_asof= DEFAULT;
189198
# End of 10.4 tests

mysql-test/suite/versioning/t/sysvars.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ SET @@global.system_versioning_asof= timestamp'2001-12-31 23:59:59.9999999';
138138
SELECT @@global.system_versioning_asof;
139139
SET @@global.system_versioning_asof= DEFAULT;
140140

141+
--echo #
142+
--echo # MDEV-23562 Assertion `time_type == MYSQL_TIMESTAMP_DATETIME' failed upon SELECT from versioned table
143+
--echo #
144+
145+
CREATE TABLE t1 (a INT) WITH SYSTEM VERSIONING;
146+
SET system_versioning_asof= DATE(NOW());
147+
SELECT * FROM t1;
148+
DROP TABLE t1;
149+
SET system_versioning_asof= DEFAULT;
150+
141151
--echo # End of 10.4 tests

sql/sys_vars.ic

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,11 @@ private:
26692669
Datetime::Options opt(TIME_CONV_NONE |
26702670
TIME_NO_ZERO_IN_DATE |
26712671
TIME_NO_ZERO_DATE, thd);
2672-
res= var->value->get_date(thd, &out.ltime, opt);
2672+
/*
2673+
var->value is allowed to return DATETIME and DATE
2674+
Make sure to convert DATE to DATETIME.
2675+
*/
2676+
res= Datetime(thd, var->value, opt).copy_to_mysql_time(&out.ltime);
26732677
}
26742678
else // set DEFAULT from global var
26752679
{

0 commit comments

Comments
 (0)