summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-11-25 07:40:10 +0400
committerAlexander Barkov <bar@mariadb.org>2016-12-06 07:52:32 +0400
commit25f52725da585c425ca81fad7ad6034a0d0b1ddd (patch)
tree0acbc6b259365766ea2c4f77724acf7bbd3f3a78 /mysql-test
parent8a1c0d46eb771958c2c7d389aed5bd6c05035cbd (diff)
downloadmariadb-git-25f52725da585c425ca81fad7ad6034a0d0b1ddd.tar.gz
MDEV-11337 Split Item::save_in_field() into virtual methods in Type_handler
Also fixes: MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type) MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR) This patch does the following: 1. Splits the function Item::save_in_field() into pieces: - Item::save_str_in_field() - Item::save_real_in_field() - Item::save_decimal_in_field() - Item::save_int_in_field() 2. Adds the missing "no_conversion" parameters to Item::save_time_in_field() and Item::save_date_in_field(), so this parameter is now correctly passed to set_field_to_null_with_conversions(). This fixes the problem reported in 11333. 3. Introduces a new virtual method Type_handler::Item_save_in_field() and uses the methods Item::save_xxx_in_field() from the implementations of Type_handler_xxx::Item_save_in_field(). These changes additionally fix the problem reported in MDEV-11331, as the old code erroneously handled expressions like COALESE(datetime-expression) through the STRING_RESULT branch of Item::save_in_field() and therefore they looked like string type expressions for the target fields. Now such expressions are correctly handled by Item::save_date_in_field().
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/default.result13
-rw-r--r--mysql-test/r/type_datetime.result21
-rw-r--r--mysql-test/r/type_timestamp.result32
-rw-r--r--mysql-test/t/default.test2
-rw-r--r--mysql-test/t/type_datetime.test21
-rw-r--r--mysql-test/t/type_timestamp.test24
6 files changed, 100 insertions, 13 deletions
diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result
index 03a444e6075..1d64f847995 100644
--- a/mysql-test/r/default.result
+++ b/mysql-test/r/default.result
@@ -986,14 +986,9 @@ t1 CREATE TABLE `t1` (
`a` decimal(30,6) DEFAULT COALESCE(CURRENT_TIMESTAMP(6))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES();
-Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
INSERT IGNORE INTO t1 VALUES();
-Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
SET sql_mode = 'STRICT_ALL_TABLES';
INSERT INTO t1 VALUES();
-ERROR 01000: Data truncated for column 'a' at row 1
SET sql_mode = DEFAULT;
DROP TABLE t1;
#
@@ -1006,8 +1001,6 @@ t1 CREATE TABLE `t1` (
`a` decimal(30,6) DEFAULT COALESCE(CURRENT_TIME(6))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES();
-Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
#
# DECIMAL + CURRENT_DATE, no truncation
@@ -1019,8 +1012,6 @@ t1 CREATE TABLE `t1` (
`a` decimal(30,6) DEFAULT COALESCE(CURRENT_DATE)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES();
-Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
DROP TABLE t1;
#
# COALESCE for SQL Standard <datetime value function>
@@ -1077,10 +1068,10 @@ t1 CREATE TABLE `t1` (
INSERT INTO t1 VALUES ();
Warnings:
Note 1265 Data truncated for column 'a' at row 1
-Warning 1265 Data truncated for column 'b' at row 1
+Note 1265 Data truncated for column 'b' at row 1
SELECT * FROM t1;
a b
-20010101102030 2001
+20010101102030 20010101102030
DROP TABLE t1;
#
# Check DEFAULT() function
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result
index 41696aa2d7d..298d0223c69 100644
--- a/mysql-test/r/type_datetime.result
+++ b/mysql-test/r/type_datetime.result
@@ -1199,3 +1199,24 @@ DROP TABLE t1;
#
# End of 10.2 tests
#
+#
+# Start of 10.3 tests
+#
+#
+# MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type)
+#
+SET timestamp=UNIX_TIMESTAMP('2001-02-03 10:00:00');
+CREATE TABLE t1 (a DATETIME);
+INSERT INTO t1 VALUES (TIME'10:20:30');
+INSERT INTO t1 VALUES (COALESCE(TIME'10:20:30'));
+INSERT INTO t1 VALUES (LEAST(TIME'10:20:30',TIME'10:20:30'));
+SELECT * FROM t1;
+a
+2001-02-03 10:20:30
+2001-02-03 10:20:30
+2001-02-03 10:20:30
+DROP TABLE t1;
+SET timestamp=DEFAULT;
+#
+# End of 10.3 tests
+#
diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result
index 69c9f68811d..d4afed8d4f8 100644
--- a/mysql-test/r/type_timestamp.result
+++ b/mysql-test/r/type_timestamp.result
@@ -950,3 +950,35 @@ DROP TABLE t1;
#
# End of 10.1 tests
#
+#
+# Start of 10.3 tests
+#
+#
+# MDEV-11333 MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR)
+#
+SELECT DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR);
+DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR)
+NULL
+Warnings:
+Warning 1441 Datetime function: datetime field overflow
+CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, KEY(a)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+EXPLAIN SELECT * FROM t1 WHERE a >= DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Warning 1441 Datetime function: datetime field overflow
+EXPLAIN SELECT * FROM t1 WHERE a >= COALESCE(DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR));
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Warning 1441 Datetime function: datetime field overflow
+DROP TABLE t1;
+#
+# End of 10.3 tests
+#
diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test
index 5f00debbc3a..746556eac02 100644
--- a/mysql-test/t/default.test
+++ b/mysql-test/t/default.test
@@ -755,11 +755,9 @@ DROP TABLE t1;
CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_TIMESTAMP(6)));
SHOW CREATE TABLE t1;
-# Same as insert into t1 values ("2016-06-05 12:54:52.342095");
INSERT INTO t1 VALUES();
INSERT IGNORE INTO t1 VALUES();
SET sql_mode = 'STRICT_ALL_TABLES';
---error WARN_DATA_TRUNCATED
INSERT INTO t1 VALUES();
SET sql_mode = DEFAULT;
DROP TABLE t1;
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index b16d426ab70..1809f304457 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -751,3 +751,24 @@ DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
+
+--echo #
+--echo # Start of 10.3 tests
+--echo #
+
+--echo #
+--echo # MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type)
+--echo #
+SET timestamp=UNIX_TIMESTAMP('2001-02-03 10:00:00');
+CREATE TABLE t1 (a DATETIME);
+INSERT INTO t1 VALUES (TIME'10:20:30');
+INSERT INTO t1 VALUES (COALESCE(TIME'10:20:30'));
+INSERT INTO t1 VALUES (LEAST(TIME'10:20:30',TIME'10:20:30'));
+SELECT * FROM t1;
+DROP TABLE t1;
+SET timestamp=DEFAULT;
+
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test
index 460769f8961..2dad92b6b90 100644
--- a/mysql-test/t/type_timestamp.test
+++ b/mysql-test/t/type_timestamp.test
@@ -555,3 +555,27 @@ let defval='0000-00-00 00:00:00';
--echo #
--echo # End of 10.1 tests
--echo #
+
+--echo #
+--echo # Start of 10.3 tests
+--echo #
+
+--echo #
+--echo # MDEV-11333 MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR)
+--echo #
+
+SELECT DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR);
+CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, KEY(a)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+INSERT INTO t1 VALUES('2001-01-01'),('2002-02-02'),('2003-03-03');
+EXPLAIN SELECT * FROM t1 WHERE a >= DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR);
+EXPLAIN SELECT * FROM t1 WHERE a >= COALESCE(DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR));
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.3 tests
+--echo #