From 114e5b8ddb26aff34f9ea8418dfe73043b912f0f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Feb 2007 09:37:34 +0100 Subject: [PATCH 1/2] Bug#23240 --init-file statements with NOW() reports '1970-01-01 11:00:00'as the date time - Starting time of a query sent by file bootstrapping wasn't initialized and starting time defaulted to 0. This later used value by the Now- item and is translated to 1970-01-01 11:00:00. - marking the time with thd->set_time() before the call to mysql_parse resolves this issue. mysql-test/r/init_file.result: Appended test case mysql-test/std_data/init_file.dat: Appended test case mysql-test/t/init_file.test: Appended test case --- mysql-test/r/init_file.result | 7 +++++++ mysql-test/std_data/init_file.dat | 8 ++++++++ mysql-test/t/init_file.test | 9 +++++++++ sql/sql_parse.cc | 1 + 4 files changed, 25 insertions(+) diff --git a/mysql-test/r/init_file.result b/mysql-test/r/init_file.result index 5404a7b2064..509d382aadd 100644 --- a/mysql-test/r/init_file.result +++ b/mysql-test/r/init_file.result @@ -1,2 +1,9 @@ +INSERT INTO init_file.startup VALUES ( NOW() ); +SELECT * INTO @X FROM init_file.startup limit 0,1; +SELECT * INTO @Y FROM init_file.startup limit 1,1; +SELECT YEAR(@X)-YEAR(@Y); +YEAR(@X)-YEAR(@Y) +0 +DROP DATABASE init_file; ok End of 4.1 tests diff --git a/mysql-test/std_data/init_file.dat b/mysql-test/std_data/init_file.dat index 6105ca2ac1b..91e456e725d 100644 --- a/mysql-test/std_data/init_file.dat +++ b/mysql-test/std_data/init_file.dat @@ -1 +1,9 @@ select * from mysql.user as t1, mysql.user as t2, mysql.user as t3; + +# +# Bug#23240 --init-file statements with NOW() reports '1970-01-01 11:00:00'as the date time +# +CREATE DATABASE IF NOT EXISTS init_file; +CREATE TABLE IF NOT EXISTS init_file.startup ( startdate DATETIME ); +INSERT INTO init_file.startup VALUES ( NOW() ); + diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test index bbe0c4ff884..34d738415c8 100644 --- a/mysql-test/t/init_file.test +++ b/mysql-test/t/init_file.test @@ -6,5 +6,14 @@ # mysql-test/t/init_file-master.opt for the actual test # +# +# Bug#23240 --init-file statements with NOW() reports '1970-01-01 11:00:00'as the date time +# +INSERT INTO init_file.startup VALUES ( NOW() ); +SELECT * INTO @X FROM init_file.startup limit 0,1; +SELECT * INTO @Y FROM init_file.startup limit 1,1; +SELECT YEAR(@X)-YEAR(@Y); +DROP DATABASE init_file; + --echo ok --echo End of 4.1 tests diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 19add72c23e..7db78a7d013 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1175,6 +1175,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); break; } + thd->set_time(); mysql_parse(thd,thd->query,length); close_thread_tables(thd); // Free tables if (thd->is_fatal_error) From a48276798b77fe4846ba5a7f74281cc1c9814357 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Feb 2007 14:57:54 +0100 Subject: [PATCH 2/2] Bug#23240 --init_file statements with NOW() reports '1970-01-01 11:00:00'as the date time - Starting time of a query sent by bootstrapping wasn't initialized and starting time defaulted to 0. This later used value by NOW- item and was translated to 1970-01-01 11:00:00. - Marketing the time with thd->set_time() before the call to mysql_parse resolves this issue. - set_time was refactored to be part of the thd->init_for_queries- process. mysql-test/r/init_file.result: Manual merge from 4.1 mysql-test/std_data/init_file.dat: Manual merge from 4.1 sql/sql_class.cc: - Moved set_time into init_for_queries process. --- mysql-test/r/init_file.result | 7 +++++++ mysql-test/std_data/init_file.dat | 9 +++++++++ sql/sql_class.cc | 1 + sql/sql_parse.cc | 3 +-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/init_file.result b/mysql-test/r/init_file.result index 1569f2c3d68..6394014f3e5 100644 --- a/mysql-test/r/init_file.result +++ b/mysql-test/r/init_file.result @@ -1,3 +1,10 @@ +INSERT INTO init_file.startup VALUES ( NOW() ); +SELECT * INTO @X FROM init_file.startup limit 0,1; +SELECT * INTO @Y FROM init_file.startup limit 1,1; +SELECT YEAR(@X)-YEAR(@Y); +YEAR(@X)-YEAR(@Y) +0 +DROP DATABASE init_file; ok end of 4.1 tests select * from t1; diff --git a/mysql-test/std_data/init_file.dat b/mysql-test/std_data/init_file.dat index 814e968eb31..cb8e0778438 100644 --- a/mysql-test/std_data/init_file.dat +++ b/mysql-test/std_data/init_file.dat @@ -27,3 +27,12 @@ insert into t2 values (11), (13); drop procedure p1; drop function f1; drop view v1; + +# +# Bug#23240 --init-file statements with NOW() reports '1970-01-01 11:00:00'as the date time +# +CREATE DATABASE IF NOT EXISTS init_file; +CREATE TABLE IF NOT EXISTS init_file.startup ( startdate DATETIME ); +INSERT INTO init_file.startup VALUES ( NOW() ); + + diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3b612dadcd0..48ed6df5178 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -317,6 +317,7 @@ void THD::init(void) void THD::init_for_queries() { + set_time(); ha_enable_transaction(this,TRUE); reset_root_defaults(mem_root, variables.query_alloc_block_size, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b3f31b7e30c..19d7a87f0ee 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1160,7 +1160,6 @@ pthread_handler_t handle_one_connection(void *arg) thd->version= refresh_version; thd->proc_info= 0; thd->command= COM_SLEEP; - thd->set_time(); thd->init_for_queries(); if (sys_init_connect.value_length && !(sctx->master_access & SUPER_ACL)) @@ -1176,7 +1175,6 @@ pthread_handler_t handle_one_connection(void *arg) sql_print_warning("%s", net->last_error); } thd->proc_info=0; - thd->set_time(); thd->init_for_queries(); } @@ -1306,6 +1304,7 @@ pthread_handler_t handle_bootstrap(void *arg) mode we have only one thread. */ thd->query_id=next_query_id(); + thd->set_time(); mysql_parse(thd,thd->query,length); close_thread_tables(thd); // Free tables if (thd->is_fatal_error)