← Back to team overview

maria-developers team mailing list archive

Please review: MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value

 

Hi Sergei,

Please review a patch for mdev-7824.

It's based on a MySQL patch for
http://bugs.mysql.com/bug.php?id=68041

and is a blocker for:

MDEV-3929 Add full support for auto-initialized/updated timestamp and datetime


Thanks.
diff --git a/mysql-test/include/type_temporal_zero_default.inc b/mysql-test/include/type_temporal_zero_default.inc
new file mode 100644
index 0000000..bac891f
--- /dev/null
+++ b/mysql-test/include/type_temporal_zero_default.inc
@@ -0,0 +1,42 @@
+--echo #
+--echo # MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+--echo #
+
+SET sql_mode=DEFAULT;
+eval CREATE TABLE t1 (a $type DEFAULT $defval);
+SET sql_mode=traditional;
+--error ER_TRUNCATED_WRONG_VALUE
+eval INSERT INTO t1 VALUES ($defval);
+--error ER_TRUNCATED_WRONG_VALUE
+INSERT INTO t1 VALUES ();
+--error ER_TRUNCATED_WRONG_VALUE
+INSERT INTO t1 VALUES (DEFAULT);
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+eval CREATE TABLE t1 (a $type NOT NULL DEFAULT $defval);
+eval CREATE TABLE t2 (a $type NOT NULL DEFAULT $defval);
+eval INSERT INTO t2 VALUES ($defval);
+SET sql_mode=traditional;
+--error ER_TRUNCATED_WRONG_VALUE
+INSERT INTO t1 (a) SELECT a FROM t2;
+DROP TABLE t1, t2;
+SET sql_mode=DEFAULT;
+
+--eval CREATE TABLE t1 (a $type DEFAULT $defval)
+--eval INSERT INTO t1 VALUES (DEFAULT);
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/mdev-7824.txt' FROM t1
+DELETE FROM t1;
+SET sql_mode=TRADITIONAL;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error ER_TRUNCATED_WRONG_VALUE
+--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/mdev-7824.txt' INTO TABLE t1
+--remove_file $MYSQLTEST_VARDIR/tmp/mdev-7824.txt
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+
+--echo #
+--echo # End of MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+--echo #
diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result
index 398f7b8..9ab452e 100644
--- a/mysql-test/r/type_date.result
+++ b/mysql-test/r/type_date.result
@@ -438,3 +438,43 @@ id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
 1
 drop table t1;
+#
+# Start of 10.1 tests
+#
+#
+# MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATE DEFAULT '0000-00-00');
+SET sql_mode=traditional;
+INSERT INTO t1 VALUES ('0000-00-00');
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
+INSERT INTO t1 VALUES ();
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
+INSERT INTO t1 VALUES (DEFAULT);
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATE NOT NULL DEFAULT '0000-00-00');
+CREATE TABLE t2 (a DATE NOT NULL DEFAULT '0000-00-00');
+INSERT INTO t2 VALUES ('0000-00-00');
+SET sql_mode=traditional;
+INSERT INTO t1 (a) SELECT a FROM t2;
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
+DROP TABLE t1, t2;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATE DEFAULT '0000-00-00');
+INSERT INTO t1 VALUES (DEFAULT);;
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' FROM t1;
+DELETE FROM t1;
+SET sql_mode=TRADITIONAL;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' INTO TABLE t1;
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
+# End of MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+#
+# End of 10.1 tests
+#
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result
index fc1946b..55b8f9a 100644
--- a/mysql-test/r/type_datetime.result
+++ b/mysql-test/r/type_datetime.result
@@ -836,3 +836,43 @@ DROP TABLE t1,t2;
 #
 # End of 5.5 tests
 #
+#
+# Start of 10.1 tests
+#
+#
+# MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATETIME DEFAULT '0000-00-00 00:00:00');
+SET sql_mode=traditional;
+INSERT INTO t1 VALUES ('0000-00-00 00:00:00');
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+INSERT INTO t1 VALUES ();
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+INSERT INTO t1 VALUES (DEFAULT);
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00');
+CREATE TABLE t2 (a DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00');
+INSERT INTO t2 VALUES ('0000-00-00 00:00:00');
+SET sql_mode=traditional;
+INSERT INTO t1 (a) SELECT a FROM t2;
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1, t2;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a DATETIME DEFAULT '0000-00-00 00:00:00');
+INSERT INTO t1 VALUES (DEFAULT);;
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' FROM t1;
+DELETE FROM t1;
+SET sql_mode=TRADITIONAL;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' INTO TABLE t1;
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
+# End of MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+#
+# End of 10.1 tests
+#
diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result
index 556e540..54a8644 100644
--- a/mysql-test/r/type_timestamp.result
+++ b/mysql-test/r/type_timestamp.result
@@ -706,5 +706,39 @@ Warnings:
 Warning	1292	Incorrect datetime value: '0000-00-00 00:00:00'
 DROP TABLE t1;
 #
+# MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a TIMESTAMP DEFAULT '0000-00-00 00:00:00');
+SET sql_mode=traditional;
+INSERT INTO t1 VALUES ('0000-00-00 00:00:00');
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+INSERT INTO t1 VALUES ();
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+INSERT INTO t1 VALUES (DEFAULT);
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00');
+CREATE TABLE t2 (a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00');
+INSERT INTO t2 VALUES ('0000-00-00 00:00:00');
+SET sql_mode=traditional;
+INSERT INTO t1 (a) SELECT a FROM t2;
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1, t2;
+SET sql_mode=DEFAULT;
+CREATE TABLE t1 (a TIMESTAMP DEFAULT '0000-00-00 00:00:00');
+INSERT INTO t1 VALUES (DEFAULT);;
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' FROM t1;
+DELETE FROM t1;
+SET sql_mode=TRADITIONAL;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/mdev-7824.txt' INTO TABLE t1;
+ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
+# End of MDEV-7824 [Bug #68041] Zero date can be inserted in strict no-zero mode through a default value
+#
+#
 # End of 10.1 tests
 #
diff --git a/mysql-test/suite/funcs_1/r/innodb_func_view.result b/mysql-test/suite/funcs_1/r/innodb_func_view.result
index b91f1a0..38ad472 100644
--- a/mysql-test/suite/funcs_1/r/innodb_func_view.result
+++ b/mysql-test/suite/funcs_1/r/innodb_func_view.result
@@ -14,7 +14,7 @@ ALTER TABLE t1_values ADD my_varbinary_1000 VARBINARY(1000);
 ALTER TABLE t1_values ADD my_datetime       DATETIME;
 ALTER TABLE t1_values ADD my_date           DATE;
 ALTER TABLE t1_values ADD ts_dummy          TIMESTAMP;
-ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP;
+ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP NOT NULL DEFAULT '2001-01-01 10:20:30';
 ALTER TABLE t1_values ADD my_time           TIME;
 ALTER TABLE t1_values ADD my_year           YEAR;
 ALTER TABLE t1_values ADD my_bigint         BIGINT;
@@ -1276,7 +1276,7 @@ SELECT IFNULL(my_timestamp,'IS_NULL'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1288,7 +1288,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL) order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1595,7 +1595,7 @@ SELECT IF(my_timestamp IS NULL, 'IS     NULL',
 WHERE select_id = 124 OR select_id IS NULL order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1609,7 +1609,7 @@ WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 124 OR select_id IS NULL) order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1936,7 +1936,7 @@ SELECT IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -1948,7 +1948,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL) order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -2496,7 +2496,7 @@ SELECT CAST(my_timestamp AS UNSIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2508,7 +2508,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2874,7 +2874,7 @@ SELECT CAST(my_timestamp AS SIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2886,7 +2886,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -3232,7 +3232,7 @@ SELECT CAST(my_timestamp AS DECIMAL(37,2)),
 my_timestamp, id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3244,7 +3244,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3624,7 +3624,7 @@ SELECT CAST(my_timestamp AS TIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3636,7 +3636,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3970,7 +3970,7 @@ SELECT CAST(my_timestamp AS DATETIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -3982,7 +3982,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4332,7 +4332,7 @@ SELECT CAST(my_timestamp AS DATE),
 my_timestamp, id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4344,7 +4344,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4690,7 +4690,7 @@ SELECT CAST(my_timestamp AS CHAR),
 my_timestamp, id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4702,7 +4702,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5002,7 +5002,7 @@ SELECT CAST(my_timestamp AS BINARY),
 my_timestamp, id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5014,7 +5014,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
diff --git a/mysql-test/suite/funcs_1/r/memory_func_view.result b/mysql-test/suite/funcs_1/r/memory_func_view.result
index 250ef44..f3eb50c 100644
--- a/mysql-test/suite/funcs_1/r/memory_func_view.result
+++ b/mysql-test/suite/funcs_1/r/memory_func_view.result
@@ -15,7 +15,7 @@ ALTER TABLE t1_values ADD my_varbinary_1000 VARBINARY(1000);
 ALTER TABLE t1_values ADD my_datetime       DATETIME;
 ALTER TABLE t1_values ADD my_date           DATE;
 ALTER TABLE t1_values ADD ts_dummy          TIMESTAMP;
-ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP;
+ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP NOT NULL DEFAULT '2001-01-01 10:20:30';
 ALTER TABLE t1_values ADD my_time           TIME;
 ALTER TABLE t1_values ADD my_year           YEAR;
 ALTER TABLE t1_values ADD my_bigint         BIGINT;
@@ -1277,7 +1277,7 @@ SELECT IFNULL(my_timestamp,'IS_NULL'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1289,7 +1289,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL) order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1596,7 +1596,7 @@ SELECT IF(my_timestamp IS NULL, 'IS     NULL',
 WHERE select_id = 124 OR select_id IS NULL order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1610,7 +1610,7 @@ WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 124 OR select_id IS NULL) order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1937,7 +1937,7 @@ SELECT IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -1949,7 +1949,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL) order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -2497,7 +2497,7 @@ SELECT CAST(my_timestamp AS UNSIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2509,7 +2509,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2875,7 +2875,7 @@ SELECT CAST(my_timestamp AS SIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2887,7 +2887,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -3233,7 +3233,7 @@ SELECT CAST(my_timestamp AS DECIMAL(37,2)),
 my_timestamp, id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3245,7 +3245,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3625,7 +3625,7 @@ SELECT CAST(my_timestamp AS TIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3637,7 +3637,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3971,7 +3971,7 @@ SELECT CAST(my_timestamp AS DATETIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -3983,7 +3983,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4333,7 +4333,7 @@ SELECT CAST(my_timestamp AS DATE),
 my_timestamp, id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4345,7 +4345,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4691,7 +4691,7 @@ SELECT CAST(my_timestamp AS CHAR),
 my_timestamp, id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4703,7 +4703,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5003,7 +5003,7 @@ SELECT CAST(my_timestamp AS BINARY),
 my_timestamp, id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5015,7 +5015,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
diff --git a/mysql-test/suite/funcs_1/r/myisam_func_view.result b/mysql-test/suite/funcs_1/r/myisam_func_view.result
index 250ef44..f3eb50c 100644
--- a/mysql-test/suite/funcs_1/r/myisam_func_view.result
+++ b/mysql-test/suite/funcs_1/r/myisam_func_view.result
@@ -15,7 +15,7 @@ ALTER TABLE t1_values ADD my_varbinary_1000 VARBINARY(1000);
 ALTER TABLE t1_values ADD my_datetime       DATETIME;
 ALTER TABLE t1_values ADD my_date           DATE;
 ALTER TABLE t1_values ADD ts_dummy          TIMESTAMP;
-ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP;
+ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP NOT NULL DEFAULT '2001-01-01 10:20:30';
 ALTER TABLE t1_values ADD my_time           TIME;
 ALTER TABLE t1_values ADD my_year           YEAR;
 ALTER TABLE t1_values ADD my_bigint         BIGINT;
@@ -1277,7 +1277,7 @@ SELECT IFNULL(my_timestamp,'IS_NULL'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1289,7 +1289,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 136 OR select_id IS NULL) order by id;
 IFNULL(my_timestamp,'IS_NULL')	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -1596,7 +1596,7 @@ SELECT IF(my_timestamp IS NULL, 'IS     NULL',
 WHERE select_id = 124 OR select_id IS NULL order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1610,7 +1610,7 @@ WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 124 OR select_id IS NULL) order by id;
 IF(my_timestamp IS NULL, 'IS     NULL',
 'IS NOT NULL')	my_timestamp	id
-IS NOT NULL	0000-00-00 00:00:00	1
+IS NOT NULL	2001-01-01 10:20:30	1
 IS NOT NULL	1970-01-01 14:00:01	2
 IS NOT NULL	2038-01-01 02:59:59	3
 IS NOT NULL	2004-02-29 23:59:59	4
@@ -1937,7 +1937,7 @@ SELECT IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE'),
 my_timestamp, id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -1949,7 +1949,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 112 OR select_id IS NULL) order by id;
 IF(my_timestamp, 'IS     TRUE', 'IS NOT TRUE')	my_timestamp	id
-IS NOT TRUE	0000-00-00 00:00:00	1
+IS     TRUE	2001-01-01 10:20:30	1
 IS     TRUE	1970-01-01 14:00:01	2
 IS     TRUE	2038-01-01 02:59:59	3
 IS     TRUE	2004-02-29 23:59:59	4
@@ -2497,7 +2497,7 @@ SELECT CAST(my_timestamp AS UNSIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2509,7 +2509,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 92 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS UNSIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2875,7 +2875,7 @@ SELECT CAST(my_timestamp AS SIGNED INTEGER),
 my_timestamp, id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -2887,7 +2887,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 80 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS SIGNED INTEGER)	my_timestamp	id
-0	0000-00-00 00:00:00	1
+20010101102030	2001-01-01 10:20:30	1
 19700101140001	1970-01-01 14:00:01	2
 20380101025959	2038-01-01 02:59:59	3
 20040229235959	2004-02-29 23:59:59	4
@@ -3233,7 +3233,7 @@ SELECT CAST(my_timestamp AS DECIMAL(37,2)),
 my_timestamp, id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3245,7 +3245,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 68 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DECIMAL(37,2))	my_timestamp	id
-0.00	0000-00-00 00:00:00	1
+20010101102030.00	2001-01-01 10:20:30	1
 19700101140001.00	1970-01-01 14:00:01	2
 20380101025959.00	2038-01-01 02:59:59	3
 20040229235959.00	2004-02-29 23:59:59	4
@@ -3625,7 +3625,7 @@ SELECT CAST(my_timestamp AS TIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3637,7 +3637,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 56 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS TIME)	my_timestamp	id
-00:00:00	0000-00-00 00:00:00	1
+10:20:30	2001-01-01 10:20:30	1
 14:00:01	1970-01-01 14:00:01	2
 02:59:59	2038-01-01 02:59:59	3
 23:59:59	2004-02-29 23:59:59	4
@@ -3971,7 +3971,7 @@ SELECT CAST(my_timestamp AS DATETIME),
 my_timestamp, id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -3983,7 +3983,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 45 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATETIME)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4333,7 +4333,7 @@ SELECT CAST(my_timestamp AS DATE),
 my_timestamp, id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4345,7 +4345,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 34 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS DATE)	my_timestamp	id
-0000-00-00	0000-00-00 00:00:00	1
+2001-01-01	2001-01-01 10:20:30	1
 1970-01-01	1970-01-01 14:00:01	2
 2038-01-01	2038-01-01 02:59:59	3
 2004-02-29	2004-02-29 23:59:59	4
@@ -4691,7 +4691,7 @@ SELECT CAST(my_timestamp AS CHAR),
 my_timestamp, id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -4703,7 +4703,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 23 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS CHAR)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5003,7 +5003,7 @@ SELECT CAST(my_timestamp AS BINARY),
 my_timestamp, id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
@@ -5015,7 +5015,7 @@ SELECT v1.* FROM v1
 WHERE v1.id IN (SELECT id FROM t1_values
 WHERE select_id = 11 OR select_id IS NULL) order by id;
 CAST(my_timestamp AS BINARY)	my_timestamp	id
-0000-00-00 00:00:00	0000-00-00 00:00:00	1
+2001-01-01 10:20:30	2001-01-01 10:20:30	1
 1970-01-01 14:00:01	1970-01-01 14:00:01	2
 2038-01-01 02:59:59	2038-01-01 02:59:59	3
 2004-02-29 23:59:59	2004-02-29 23:59:59	4
diff --git a/mysql-test/suite/funcs_1/views/func_view.inc b/mysql-test/suite/funcs_1/views/func_view.inc
index 1f0b0ac..5bd3047 100644
--- a/mysql-test/suite/funcs_1/views/func_view.inc
+++ b/mysql-test/suite/funcs_1/views/func_view.inc
@@ -210,7 +210,7 @@ ALTER TABLE t1_values ADD my_varbinary_1000 VARBINARY(1000);
 ALTER TABLE t1_values ADD my_datetime       DATETIME;
 ALTER TABLE t1_values ADD my_date           DATE;
 ALTER TABLE t1_values ADD ts_dummy          TIMESTAMP;
-ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP;
+ALTER TABLE t1_values ADD my_timestamp      TIMESTAMP NOT NULL DEFAULT '2001-01-01 10:20:30';
 ALTER TABLE t1_values ADD my_time           TIME;
 ALTER TABLE t1_values ADD my_year           YEAR;
 ALTER TABLE t1_values ADD my_bigint         BIGINT;
diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test
index 6b8ed12..53627c6 100644
--- a/mysql-test/t/type_date.test
+++ b/mysql-test/t/type_date.test
@@ -385,3 +385,14 @@ select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
 select 1 from t1 as t1_0 inner join t1 as t2 on (t1_0.a <=> now()) join t1 on 1;
 drop table t1;
 
+--echo #
+--echo # Start of 10.1 tests
+--echo #
+
+let type=DATE;
+let defval='0000-00-00';
+--source include/type_temporal_zero_default.inc
+
+--echo #
+--echo # End of 10.1 tests
+--echo #
diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test
index e44b190..f3e603e 100644
--- a/mysql-test/t/type_datetime.test
+++ b/mysql-test/t/type_datetime.test
@@ -613,3 +613,15 @@ DROP TABLE t1,t2;
 --echo #
 --echo # End of 5.5 tests
 --echo #
+
+--echo #
+--echo # Start of 10.1 tests
+--echo #
+
+let type=DATETIME;
+let defval='0000-00-00 00:00:00';
+--source include/type_temporal_zero_default.inc
+
+--echo #
+--echo # End of 10.1 tests
+--echo #
diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test
index ed5a57b..ef00d40 100644
--- a/mysql-test/t/type_timestamp.test
+++ b/mysql-test/t/type_timestamp.test
@@ -506,6 +506,10 @@ INSERT INTO t1 VALUES ('0000-00-00 00:00:00');
 SELECT DATE_ADD(a, INTERVAL 10 SECOND) FROM t1;
 DROP TABLE t1;
 
+let type=TIMESTAMP;
+let defval='0000-00-00 00:00:00';
+--source include/type_temporal_zero_default.inc
+
 
 --echo #
 --echo # End of 10.1 tests
diff --git a/sql/field.cc b/sql/field.cc
index e99f48d..65c8ec2 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4832,6 +4832,21 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
 }
 
 
+bool Field_timestamp::validate_stored_val(THD *thd)
+{
+  ulong sec_part;
+  if (is_real_null() || get_timestamp(&sec_part) || sec_part ||
+      (sql_mode_for_dates(thd) & TIME_NO_ZERO_DATE) == 0)
+    return false;
+  MYSQL_TIME ltime;
+  set_zero_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
+  ErrConvTime str(&ltime);
+  set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
+                       &str, MYSQL_TIMESTAMP_DATETIME, 1);
+  return true;
+}
+
+
 bool Field_timestamp::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
 {
   THD *thd= get_thd();
@@ -5158,6 +5173,20 @@ void Field_temporal::set_warnings(Sql_condition::enum_warning_level trunc_level,
 }
 
 
+bool Field_temporal_with_date::validate_stored_val(THD *thd)
+{
+  MYSQL_TIME ltime;
+  if (is_real_null() || !get_date(&ltime, sql_mode_for_dates(thd)))
+    return false;
+  if (get_date(&ltime, 0))
+    set_zero_time(&ltime, MYSQL_TIMESTAMP_DATE); // Safety
+  ErrConvTime str(&ltime);
+  set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
+                       &str, ltime.time_type, 1);
+  return true;
+}
+
+
 /*
   Store string into a date/time field
 
diff --git a/sql/field.h b/sql/field.h
index 65a71fc..3e26902 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -950,6 +950,8 @@ class Field
     flags |= (column_format_arg << FIELD_FLAGS_COLUMN_FORMAT);
   }
 
+  virtual bool validate_stored_val(THD *thd) { return false; }
+
   key_map get_possible_keys();
 
   /* Hash value */
@@ -1680,6 +1682,7 @@ class Field_temporal_with_date: public Field_temporal {
   int  store(longlong nr, bool unsigned_val);
   int  store_time_dec(MYSQL_TIME *ltime, uint dec);
   int  store_decimal(const my_decimal *);
+  bool validate_stored_val(THD *thd);
 };
 
 
@@ -1748,6 +1751,7 @@ class Field_timestamp :public Field_temporal {
   {
     return unpack_int32(to, from, from_end);
   }
+  bool validate_stored_val(THD *thd);
   uint size_of() const { return sizeof(*this); }
 };
 
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index e31f7c5..14f2947 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -859,7 +859,8 @@ bool memcpy_field_possible(Field *to,Field *from)
           from->charset() == to->charset() &&
           (!sql_mode_for_dates(to->table->in_use) ||
            (from->type()!= MYSQL_TYPE_DATE &&
-            from->type()!= MYSQL_TYPE_DATETIME)) &&
+            from->type()!= MYSQL_TYPE_DATETIME &&
+            from->type()!= MYSQL_TYPE_TIMESTAMP)) &&
           (from_real_type != MYSQL_TYPE_VARCHAR ||
            ((Field_varstring*)from)->length_bytes ==
            ((Field_varstring*)to)->length_bytes));
diff --git a/sql/item.cc b/sql/item.cc
index c8a9164..0fdc001 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -8207,7 +8207,7 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
       return 1;
     }
     field_arg->set_default();
-    return 0;
+    return field_arg->validate_stored_val(current_thd) ? -1 : 0;
   }
   return Item_field::save_in_field(field_arg, no_conversions);
 }
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 24d75d9..45b0b82 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -876,7 +876,11 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
   {
     if (fields.elements || !value_count)
     {
-      restore_record(table,s->default_values);	// Get empty record
+      if (table->restore_record_and_validate_unset_fields(thd))
+      {
+        error= 1;
+        break;
+      }
       if (fill_record_n_invoke_before_triggers(thd, table, fields, *values, 0,
                                                TRG_EVENT_INSERT))
       {
@@ -3654,8 +3658,11 @@ int select_insert::send_data(List<Item> &values)
 void select_insert::store_values(List<Item> &values)
 {
   if (fields->elements)
-    fill_record_n_invoke_before_triggers(thd, table, *fields, values, 1,
-                                         TRG_EVENT_INSERT);
+  {
+    if (!table->restore_record_and_validate_unset_fields(thd))
+      fill_record_n_invoke_before_triggers(thd, table, *fields, values, 1,
+                                           TRG_EVENT_INSERT);
+  }
   else
     fill_record_n_invoke_before_triggers(thd, table, table->field, values, 1,
                                          TRG_EVENT_INSERT);
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 18982c5..a75ce5c 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -827,7 +827,12 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
     read_info.row_end[0]=0;
 #endif
 
-    restore_record(table, s->default_values);
+    if (table->restore_record_and_validate_unset_fields(thd))
+    {
+      read_info.error= true;
+      break;
+    }
+    
     /*
       There is no variables in fields_vars list in this format so
       this conversion is safe.
@@ -967,7 +972,12 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
                             thd->progress.max_counter);
       }
     }
-    restore_record(table, s->default_values);
+
+    if (table->restore_record_and_validate_unset_fields(thd))
+    {
+      read_info.error= true;
+      break;
+    }
 
     while ((item= it++))
     {
@@ -1195,7 +1205,11 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
     }
 #endif
     
-    restore_record(table, s->default_values);
+    if (table->restore_record_and_validate_unset_fields(thd))
+    {
+      read_info.error= true;
+      break;
+    }
     
     while ((item= it++))
     {
diff --git a/sql/table.cc b/sql/table.cc
index 5c85d56..c798212 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -6895,6 +6895,43 @@ bool TABLE::prepare_triggers_for_update_stmt_or_event()
   return FALSE;
 }
 
+
+/**
+  Validates default value of fields which are not specified in
+  the column list of INSERT statement.
+
+  @Note table->record[0] should be populated with default values
+        before calling this function.
+
+  @param thd              thread context
+
+  @return
+    @retval false Success.
+    @retval true  Failure.
+*/
+
+bool TABLE::validate_default_values_of_unset_fields(THD *thd)
+{
+  DBUG_ENTER("TABLE::validate_default_values_of_unset_fields");
+  for (Field **fld= field; *fld; fld++)
+  {
+    if (!bitmap_is_set(write_set, (*fld)->field_index) &&
+        !((*fld)->flags & NO_DEFAULT_VALUE_FLAG))
+    {
+      if ((*fld)->validate_stored_val(thd) && thd->is_error())
+        DBUG_RETURN(true);
+    }
+  }
+  DBUG_RETURN(false);
+}
+
+
+bool TABLE::restore_record_and_validate_unset_fields(THD *thd)
+{
+  restore_record(this, s->default_values);
+  return validate_default_values_of_unset_fields(thd);
+}
+
 /*
   @brief Reset const_table flag
 
diff --git a/sql/table.h b/sql/table.h
index f647184..6e14d6b 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1374,6 +1374,9 @@ struct TABLE
   void prepare_triggers_for_insert_stmt_or_event();
   bool prepare_triggers_for_delete_stmt_or_event();
   bool prepare_triggers_for_update_stmt_or_event();
+
+  bool validate_default_values_of_unset_fields(THD *thd);
+  bool restore_record_and_validate_unset_fields(THD *thd);
 };
 
 

Follow ups