diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result index c7e5cab4f8c..210c6450b70 100644 --- a/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result @@ -549,8 +549,13 @@ a BLOB GENERATED ALWAYS AS ('') VIRTUAL, b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL, KEY (a(183),b) ); +Warnings: +Warning 1901 Function or expression '''' cannot be used in the GENERATED ALWAYS AS clause of `b` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL INSERT IGNORE INTO t VALUES(), (), (); Warnings: +Warning 1901 Function or expression '''' cannot be used in the GENERATED ALWAYS AS clause of `b` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL Warning 1265 Data truncated for column 'b' at row 1 Warning 1265 Data truncated for column 'b' at row 2 Warning 1265 Data truncated for column 'b' at row 3 diff --git a/mysql-test/suite/vcol/r/vcol_keys_innodb.result b/mysql-test/suite/vcol/r/vcol_keys_innodb.result index c6c05429978..f3bbd6039eb 100644 --- a/mysql-test/suite/vcol/r/vcol_keys_innodb.result +++ b/mysql-test/suite/vcol/r/vcol_keys_innodb.result @@ -257,6 +257,11 @@ insert into t1 (col_varchar,col_int,col_datetime,col_time,col_blob,col_bit,col_y ('foo',1,'2010-05-08 13:08:12.034783','18:32:14','foo',b'0111110101001001',1992,'f',0.2,'','1994-12-26','2019-01-11 00:00:00'), ('bar',6,'1900-01-01 00:00:00','00:00:00','bar',b'10011000001101011000101',1985,'b',0.7,'','2028-04-06','1971-01-01 00:00:00'); alter table t1 add index(vcol_datetime); +Warnings: +Warning 1901 Function or expression '`col_datetime`' cannot be used in the GENERATED ALWAYS AS clause of `vcol_datetime` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +Warning 1901 Function or expression '`col_datetime`' cannot be used in the GENERATED ALWAYS AS clause of `vcol_datetime` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL drop table t1; create table t1 ( pk int, diff --git a/mysql-test/suite/vcol/r/vcol_sql_mode.result b/mysql-test/suite/vcol/r/vcol_sql_mode.result index 385939fd037..ecbafc87b84 100644 --- a/mysql-test/suite/vcol/r/vcol_sql_mode.result +++ b/mysql-test/suite/vcol/r/vcol_sql_mode.result @@ -26,6 +26,9 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (a CHAR(5), v TIME AS (a) VIRTUAL, KEY(v)); +Warnings: +Warning 1901 Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL DROP TABLE t1; CREATE TABLE t1 (c CHAR(8), v BINARY(8) AS (c), KEY(v)); Warnings: diff --git a/mysql-test/suite/vcol/r/vcol_sql_mode_datetime.result b/mysql-test/suite/vcol/r/vcol_sql_mode_datetime.result new file mode 100644 index 00000000000..dab13af5fff --- /dev/null +++ b/mysql-test/suite/vcol/r/vcol_sql_mode_datetime.result @@ -0,0 +1,101 @@ +# +# Start of 10.4 tests +# +# +# MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +# +SET sql_mode=DEFAULT; +# OK: same FSP + virtual index +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(4) AS (t) VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(4) AS ('2001-01-01 10:20:30.1234') VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +# OK: lower FSP + no virtual index +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS (t) VIRTUAL +); +DROP TABLE t1; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; +# NOT OK: lower FSP + virtual index +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS (t) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression '`t`' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS (COALESCE(t)) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression 'coalesce(`t`)' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression ''2001-01-01 10:20:30.1234'' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +# OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS (ROUND(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +t d v +2006-03-01 12:44:34.0496 2029-10-10 21:27:53 2006-03-01 12:44:34.050 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; +# OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t DATETIME(4), +d DATETIME, +v DATETIME(3) AS (TRUNCATE(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +t d v +2006-03-01 12:44:34.0496 2029-10-10 21:27:53 2006-03-01 12:44:34.049 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; +# +# End of 10.4 tests +# diff --git a/mysql-test/suite/vcol/r/vcol_sql_mode_time.result b/mysql-test/suite/vcol/r/vcol_sql_mode_time.result new file mode 100644 index 00000000000..8f72cd89a08 --- /dev/null +++ b/mysql-test/suite/vcol/r/vcol_sql_mode_time.result @@ -0,0 +1,101 @@ +# +# Start of 10.4 tests +# +# +# MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +# +SET sql_mode=DEFAULT; +# OK: same FSP + virtual index +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(4) AS (t) VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(4) AS ('10:20:30.1234') VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +# OK: lower FSP + no virtual index +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS (t) VIRTUAL +); +DROP TABLE t1; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; +# NOT OK: lower FSP + virtual index +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS (t) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression '`t`' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS (COALESCE(t)) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression 'coalesce(`t`)' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression ''2001-01-01 10:20:30.1234'' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +# OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS (ROUND(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('12:44:34.0496','21:27:53'); +SELECT * FROM t1; +t d v +12:44:34.0496 21:27:53 12:44:34.050 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = CURRENT_TIME; +DROP TABLE t1; +SET sql_mode=DEFAULT; +# OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t TIME(4), +d TIME, +v TIME(3) AS (TRUNCATE(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('12:44:34.0496','21:27:53'); +SELECT * FROM t1; +t d v +12:44:34.0496 21:27:53 12:44:34.049 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = CURRENT_TIME; +DROP TABLE t1; +SET sql_mode=DEFAULT; +# +# End of 10.4 tests +# diff --git a/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result b/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result new file mode 100644 index 00000000000..d9a74708477 --- /dev/null +++ b/mysql-test/suite/vcol/r/vcol_sql_mode_timestamp.result @@ -0,0 +1,101 @@ +# +# Start of 10.4 tests +# +# +# MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +# +SET sql_mode=DEFAULT; +# OK: same FSP + virtual index +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(4) AS (t) VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(4) AS ('2001-01-01 10:20:30.1234') VIRTUAL, +KEY(v,d) +); +DROP TABLE t1; +# OK: lower FSP + no virtual index +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS (t) VIRTUAL +); +DROP TABLE t1; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; +# NOT OK: lower FSP + virtual index +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS (t) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression '`t`' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS (COALESCE(t)) VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression 'coalesce(`t`)' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, +KEY(v,d) +); +Warnings: +Warning 1901 Function or expression ''2001-01-01 10:20:30.1234'' cannot be used in the GENERATED ALWAYS AS clause of `v` +Warning 1105 Expression depends on the @@sql_mode value TIME_ROUND_FRACTIONAL +DROP TABLE t1; +# OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS (ROUND(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +t d v +2006-03-01 12:44:34.0496 2029-10-10 21:27:53 2006-03-01 12:44:34.050 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; +# OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( +t TIMESTAMP(4), +d DATETIME, +v TIMESTAMP(3) AS (TRUNCATE(t,3)) VIRTUAL, +KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +t d v +2006-03-01 12:44:34.0496 2029-10-10 21:27:53 2006-03-01 12:44:34.049 +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; +# +# End of 10.4 tests +# diff --git a/mysql-test/suite/vcol/t/vcol_sql_mode_datetime.test b/mysql-test/suite/vcol/t/vcol_sql_mode_datetime.test new file mode 100644 index 00000000000..5e0e611949d --- /dev/null +++ b/mysql-test/suite/vcol/t/vcol_sql_mode_datetime.test @@ -0,0 +1,112 @@ +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +--echo # + +SET sql_mode=DEFAULT; + +--echo # OK: same FSP + virtual index + +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(4) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(4) AS ('2001-01-01 10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + no virtual index + +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS (t) VIRTUAL +); +DROP TABLE t1; + + +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; + + +--echo # NOT OK: lower FSP + virtual index + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS (COALESCE(t)) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS (ROUND(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t DATETIME(4), + d DATETIME, + v DATETIME(3) AS (TRUNCATE(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/suite/vcol/t/vcol_sql_mode_time.test b/mysql-test/suite/vcol/t/vcol_sql_mode_time.test new file mode 100644 index 00000000000..f06871b6ebc --- /dev/null +++ b/mysql-test/suite/vcol/t/vcol_sql_mode_time.test @@ -0,0 +1,112 @@ +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +--echo # + +SET sql_mode=DEFAULT; + +--echo # OK: same FSP + virtual index + +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(4) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(4) AS ('10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + no virtual index + +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS (t) VIRTUAL +); +DROP TABLE t1; + + +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; + + +--echo # NOT OK: lower FSP + virtual index + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS (COALESCE(t)) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS (ROUND(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('12:44:34.0496','21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = CURRENT_TIME; +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t TIME(4), + d TIME, + v TIME(3) AS (TRUNCATE(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('12:44:34.0496','21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = CURRENT_TIME; +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test b/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test new file mode 100644 index 00000000000..cd7f1125840 --- /dev/null +++ b/mysql-test/suite/vcol/t/vcol_sql_mode_timestamp.test @@ -0,0 +1,112 @@ +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # MDEV-18153 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIME_ROUND_FRACTIONAL +--echo # + +SET sql_mode=DEFAULT; + +--echo # OK: same FSP + virtual index + +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(4) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(4) AS ('2001-01-01 10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + no virtual index + +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS (t) VIRTUAL +); +DROP TABLE t1; + + +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL +); +DROP TABLE t1; + + +--echo # NOT OK: lower FSP + virtual index + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS (t) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS (COALESCE(t)) VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + +#--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS ('2001-01-01 10:20:30.1234') VIRTUAL, + KEY(v,d) +); +DROP TABLE t1; + + +--echo # OK: lower FSP + ROUND + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS (ROUND(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # OK: lower FSP + TRUNCATE + virtual index +SET sql_mode=DEFAULT; +CREATE TABLE t1 ( + t TIMESTAMP(4), + d DATETIME, + v TIMESTAMP(3) AS (TRUNCATE(t,3)) VIRTUAL, + KEY(v,d) +); +INSERT IGNORE INTO t1 (t,d) VALUES ('2006-03-01 12:44:34.0496','2029-10-10 21:27:53'); +SELECT * FROM t1; +SET SQL_MODE= 'TIME_ROUND_FRACTIONAL'; +UPDATE IGNORE t1 SET d = NOW(); +DROP TABLE t1; +SET sql_mode=DEFAULT; + + +--echo # +--echo # End of 10.4 tests +--echo # diff --git a/sql/field.cc b/sql/field.cc index 2eaac73a268..06dac05317c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1407,8 +1407,10 @@ bool Field::check_vcol_sql_mode_dependency(THD *thd, vcol_init_mode mode) const DBUG_ASSERT(vcol_info); if ((flags & PART_KEY_FLAG) != 0 || stored_in_db()) { + Sql_mode_dependency valdep= vcol_info->expr->value_depends_on_sql_mode(); + sql_mode_t cnvdep= conversion_depends_on_sql_mode(thd, vcol_info->expr); Sql_mode_dependency dep= - vcol_info->expr->value_depends_on_sql_mode() & + (valdep | Sql_mode_dependency(0, cnvdep)) & Sql_mode_dependency(~0, ~can_handle_sql_mode_dependency_on_store()); if (dep) { @@ -5062,6 +5064,14 @@ Field_timestamp::Field_timestamp(uchar *ptr_arg, uint32 len_arg, } +sql_mode_t +Field_timestamp::conversion_depends_on_sql_mode(THD *thd, Item *expr) const +{ + return expr->datetime_precision(thd) > decimals() ? + MODE_TIME_ROUND_FRACTIONAL : 0; +} + + int Field_timestamp::save_in_field(Field *to) { ulong sec_part; @@ -5823,6 +5833,14 @@ Item *Field_temporal::get_equal_const_item_datetime(THD *thd, ** In number context: HHMMSS ** Stored as a 3 byte unsigned int ****************************************************************************/ +sql_mode_t +Field_time::conversion_depends_on_sql_mode(THD *thd, Item *expr) const +{ + return expr->time_precision(thd) > decimals() ? + MODE_TIME_ROUND_FRACTIONAL : 0; +} + + int Field_time::store_TIME_with_warning(const Time *t, const ErrConv *str, int warn) { @@ -6727,6 +6745,15 @@ void Field_datetime::store_TIME(const MYSQL_TIME *ltime) int8store(ptr,tmp); } + +sql_mode_t +Field_datetime::conversion_depends_on_sql_mode(THD *thd, Item *expr) const +{ + return expr->datetime_precision(thd) > decimals() ? + MODE_TIME_ROUND_FRACTIONAL : 0; +} + + bool Field_datetime::send_binary(Protocol *protocol) { MYSQL_TIME tm; diff --git a/sql/field.h b/sql/field.h index 271177d4eb5..b16e738d639 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1215,6 +1215,11 @@ public: { return 0; } + virtual sql_mode_t conversion_depends_on_sql_mode(THD *thd, + Item *expr) const + { + return (sql_mode_t) 0; + } virtual sql_mode_t can_handle_sql_mode_dependency_on_store() const { return 0; @@ -2827,6 +2832,7 @@ public: const Type_handler *type_handler() const { return &type_handler_timestamp; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; } Copy_func *get_copy_func(const Field *from) const; + sql_mode_t conversion_depends_on_sql_mode(THD *, Item *) const; int store(const char *to,size_t length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); @@ -3185,6 +3191,7 @@ public: return real_type() == from->real_type() && decimals() == from->decimals(); } + sql_mode_t conversion_depends_on_sql_mode(THD *, Item *) const; int store_time_dec(const MYSQL_TIME *ltime, uint dec); int store(const char *to,size_t length,CHARSET_INFO *charset); int store(double nr); @@ -3329,6 +3336,7 @@ public: } const Type_handler *type_handler() const { return &type_handler_datetime; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; } + sql_mode_t conversion_depends_on_sql_mode(THD *, Item *) const; int store(const char *to, size_t length, CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); diff --git a/sql/sql_mode.cc b/sql/sql_mode.cc index 32d19cecbdb..6e62fa8fa24 100644 --- a/sql/sql_mode.cc +++ b/sql/sql_mode.cc @@ -17,7 +17,7 @@ #include "mariadb.h" #include "set_var.h" -void Sql_mode_dependency::push_dependency_warnings(THD *thd) +void Sql_mode_dependency::push_dependency_warnings(THD *thd) const { sql_mode_t all= m_hard | m_soft; for (uint i= 0; all ; i++, all >>= 1) diff --git a/sql/sql_mode.h b/sql/sql_mode.h index e92848fb6d1..fb2b7cefa0a 100644 --- a/sql/sql_mode.h +++ b/sql/sql_mode.h @@ -155,7 +155,7 @@ public: m_soft= 0; return *this; } - void push_dependency_warnings(THD *thd); + void push_dependency_warnings(THD *thd) const; };