diff options
author | unknown <aelkin@mysql.com> | 2006-03-10 16:47:56 +0200 |
---|---|---|
committer | unknown <aelkin@mysql.com> | 2006-03-10 16:47:56 +0200 |
commit | 8f543b5eb8daccc3d58a6856fa71ae34fec2ccf4 (patch) | |
tree | 67d0f445b3cd9e840e9096f915f396e07eabc134 | |
parent | 696367399bd1013b5db7701659117dde9297f08c (diff) | |
download | mariadb-git-8f543b5eb8daccc3d58a6856fa71ae34fec2ccf4.tar.gz |
BUG#15101 SYSDATE() disregards SET TIMESTAMP.
After the ChangeSet 1.1892.20.1 2005/08/24 (Bug #12562) SYSDATE() is not an alias
of NOW() and is unsafe for replication.
`SYSDATE()' backward compatible aliasing clashes with the idea #12562
fix. To make it safe-replicatable we have to either use RBR or to restore
the pre-5.0 style.
--sysdate-is-now command line flag was introduced to provide backward compatibility.
sql/mysqld.cc:
New option to force SYSDATE's backward compatible with 4.1 aliasing to NOW (not default)
sql/sql_class.h:
new slot to fill at init time and check at parse
sql/sql_yacc.yy:
calling NOW's branches when --sysdate-is-now
mysql-test/r/sysdate_is_now.result:
New BitKeeper file ``mysql-test/r/sysdate_is_now.result''
mysql-test/t/sysdate_is_now-master.opt:
New BitKeeper file ``mysql-test/t/sysdate_is_now-master.opt''
mysql-test/t/sysdate_is_now.test:
New BitKeeper file ``mysql-test/t/sysdate_is_now.test''
-rw-r--r-- | mysql-test/r/sysdate_is_now.result | 4 | ||||
-rw-r--r-- | mysql-test/t/sysdate_is_now-master.opt | 1 | ||||
-rw-r--r-- | mysql-test/t/sysdate_is_now.test | 11 | ||||
-rw-r--r-- | sql/mysqld.cc | 5 | ||||
-rw-r--r-- | sql/sql_class.h | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 14 |
6 files changed, 34 insertions, 2 deletions
diff --git a/mysql-test/r/sysdate_is_now.result b/mysql-test/r/sysdate_is_now.result new file mode 100644 index 00000000000..82861436ff6 --- /dev/null +++ b/mysql-test/r/sysdate_is_now.result @@ -0,0 +1,4 @@ +set timestamp=1; +SELECT sleep(1),NOW()-SYSDATE() as zero; +sleep(1) zero +0 0 diff --git a/mysql-test/t/sysdate_is_now-master.opt b/mysql-test/t/sysdate_is_now-master.opt new file mode 100644 index 00000000000..97a58d28032 --- /dev/null +++ b/mysql-test/t/sysdate_is_now-master.opt @@ -0,0 +1 @@ +--sysdate-is-now diff --git a/mysql-test/t/sysdate_is_now.test b/mysql-test/t/sysdate_is_now.test new file mode 100644 index 00000000000..166914e20c8 --- /dev/null +++ b/mysql-test/t/sysdate_is_now.test @@ -0,0 +1,11 @@ +# +# BUG#15101 restore aliasing of SYSDATE to NOW in 5.0 +# this feature is activated via --sysdate-is-now mysqld init opt +# +# To test here +# 1. SYSDATE() does not distiguish from NOW() +# 2. SYSDATE() obeys set timestamp + +set timestamp=1; +SELECT sleep(1),NOW()-SYSDATE() as zero; +# End of 5.0 tests diff --git a/sql/mysqld.cc b/sql/mysqld.cc index bc30a2c981b..f1cffbfd657 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4578,6 +4578,7 @@ enum options_mysqld OPT_DATETIME_FORMAT, OPT_LOG_QUERIES_NOT_USING_INDEXES, OPT_DEFAULT_TIME_ZONE, + OPT_SYSDATE_IS_NOW, OPT_OPTIMIZER_SEARCH_DEPTH, OPT_OPTIMIZER_PRUNE_LEVEL, OPT_UPDATABLE_VIEWS_WITH_LIMIT, @@ -5935,6 +5936,10 @@ The minimum value for this variable is 4096.", (gptr*) &max_system_variables.net_wait_timeout, 0, GET_ULONG, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, IF_WIN(INT_MAX32/1000, LONG_TIMEOUT), 0, 1, 0}, + {"sysdate-is-now", OPT_SYSDATE_IS_NOW, + "Non-default flag to alias SYSDATE() to NOW() to be safe-replicatable. Since 5.0 SYSDATE returns a `dynamic' value different for different invocation even within a query", + (gptr*) &global_system_variables.sysdate_is_now, + 0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; diff --git a/sql/sql_class.h b/sql/sql_class.h index 048a0a49618..6189470b88d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -585,6 +585,7 @@ struct system_variables DATE_TIME_FORMAT *date_format; DATE_TIME_FORMAT *datetime_format; DATE_TIME_FORMAT *time_format; + my_bool sysdate_is_now; }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index b6d197369cf..03da97b91c9 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4671,9 +4671,19 @@ simple_expr: | SUBSTRING_INDEX '(' expr ',' expr ',' expr ')' { $$= new Item_func_substr_index($3,$5,$7); } | SYSDATE optional_braces - { $$= new Item_func_sysdate_local(); Lex->safe_to_cache_query=0;} + { + if (global_system_variables.sysdate_is_now == 0) + $$= new Item_func_sysdate_local(); + else $$= new Item_func_now_local(); + Lex->safe_to_cache_query=0; + } | SYSDATE '(' expr ')' - { $$= new Item_func_sysdate_local($3); Lex->safe_to_cache_query=0;} + { + if (global_system_variables.sysdate_is_now == 0) + $$= new Item_func_sysdate_local($3); + else $$= new Item_func_now_local($3); + Lex->safe_to_cache_query=0; + } | TIME_SYM '(' expr ')' { $$= new Item_time_typecast($3); } | TIMESTAMP '(' expr ')' |