mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
68d7b26698
Instead of trying to open time zone tables during calculation of CONVERT_TZ() function or setting of @@time_zone variable we should open and lock them with the rest of statement's table (so we should add them to global table list) and after that use such pre-opened tables for loading info about time zones. mysql-test/r/timezone2.result: Added test for bug #4508 mysql-test/t/timezone2.test: Added test for bug #4508 scripts/mysql_create_system_tables.sh: Added one more test time zone to time zone tables which is needed for test for bug #4508. sql/item_create.cc: CONVERT_TZ() now is treated as special function. sql/item_create.h: CONVERT_TZ() now is treated as special function. sql/item_timefunc.cc: Item_func_convert_tz now uses list of pre-opened time zone tables instead of trying to open them ad-hoc. Also it avoid calling of current_thd. sql/item_timefunc.h: Added comment describing special nature of CONVERT_TZ() function. Optimization: Added own fix_fields() method and tz_tables member for caching pointer to list of open time zone tables to Item_func_convert_tz class. sql/lex.h: CONVERT_TZ() now is treated as special function. sql/mysql_priv.h: Removed function which is no longer used. sql/set_var.cc: Now my_tz_find() accepts list of pre-opened time zone tables as last argument and no longer needs pointer to current THD. sql/set_var.h: Exported sys_time_zone, which is now used in sql_yacc.yy for quick finding out if we are setting @@time_zone variable. sql/sql_base.cc: Moved propagation of pointers to open tables from global list to local select lists to open_and_lock_tables(), also added implicit usage of time zone tables as condition for such propagation. sql/sql_lex.cc: Added fake_time_zone_tables_list which is used to indicate that time zone tables are implicitly used in statement. st_select_lex_unit::create_total_list(): if time zone tables are implicitly used in statement add them to global tables list. sql/sql_lex.h: Added LEX::time_zone_tables_used member which is used to indicate that time zone tables are implicitly used in this statement (by pointing to fake_time_zone_table_list) and for holding pointer to those tables after they've been opened. sql/sql_parse.cc: We should also create global table list if statement uses time zone tables implicitly. Added initialization of LEX::time_zone_tables_used to mysql_query_init(). sql/sql_prepare.cc: We should also create global table list if statement uses time zone tables implicitly. sql/sql_select.cc: Removed functions which are no longer used. sql/sql_yacc.yy: CONVERT_TZ() and @@time_zone variable are handled in special way since they implicitly use time zone tables. sql/tztime.cc: Fix for bug #4508 "CONVERT_TZ() function with new time zone as param crashes server". If statement uses CONVERT_TZ() function or @@time_zone variable is set then it implicitly uses time zone tables. We need to open and lock such tables with all other tables of such statement. All code responsible for opening table was removed from tz_load_from_db() and function was renamed to tz_load_from_open_tables() (which uses list of pre-opened tables). We also have new functions for construction and initialization of table list of time zone tables. my_tz_find() now always require list of pre-opened time zone tables and no longer needs current THD. So we have to pre-open them in my_tz_init(). Also now we try to open time zone tables only if they were found during startup. sql/tztime.h: New function for construction of table list of time zone tables my_tz_get_table_list(). Now my_tz_find() requires list of pre-pened time zone tables instead of current thread.
201 lines
6.5 KiB
Text
201 lines
6.5 KiB
Text
# This script tests our own time zone support functions
|
|
|
|
# Preparing playground
|
|
--disable_warnings
|
|
drop table if exists t1;
|
|
--enable_warnings
|
|
|
|
|
|
#
|
|
# Let us first check +HH:MM style timezones
|
|
#
|
|
create table t1 (ts timestamp);
|
|
|
|
set time_zone='+00:00';
|
|
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
|
|
insert into t1 (ts) values ('2003-03-30 02:30:00');
|
|
|
|
set time_zone='+10:30';
|
|
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
|
|
insert into t1 (ts) values ('2003-03-30 02:30:00');
|
|
|
|
set time_zone='-10:00';
|
|
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
|
|
insert into t1 (ts) values ('2003-03-30 02:30:00');
|
|
|
|
# Here we will get different results
|
|
select * from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Let us try DB specified time zones
|
|
#
|
|
select Name from mysql.time_zone_name where Name in
|
|
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow');
|
|
|
|
create table t1 (i int, ts timestamp);
|
|
|
|
set time_zone='MET';
|
|
|
|
# We check common date time value and non existent or ambiguios values
|
|
# Normal value without DST
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00');
|
|
# Values around and in spring time-gap
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'),
|
|
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'),
|
|
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00');
|
|
# Normal value with DST
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00');
|
|
# Ambiguos values (also check for determenism)
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'),
|
|
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'),
|
|
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'),
|
|
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'),
|
|
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59');
|
|
|
|
set time_zone='UTC';
|
|
|
|
select * from t1;
|
|
|
|
delete from t1;
|
|
|
|
# Simple check for 'Europe/Moscow' time zone just for showing that it works
|
|
set time_zone='Europe/Moscow';
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
|
|
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
|
|
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
|
|
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
|
|
select * from t1;
|
|
delete from t1;
|
|
|
|
|
|
#
|
|
# Check for time zone with leap seconds
|
|
# Values in ts column must be the same but values in i column should
|
|
# differ from corresponding values for Europe/Moscow a bit.
|
|
#
|
|
set time_zone='leap/Europe/Moscow';
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'),
|
|
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'),
|
|
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'),
|
|
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00');
|
|
select * from t1;
|
|
delete from t1;
|
|
# Let us test leap jump
|
|
insert into t1 (i, ts) values
|
|
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'),
|
|
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00');
|
|
select * from t1;
|
|
# Additional 60ieth second!
|
|
select from_unixtime(362793609);
|
|
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Let us test range for TIMESTAMP
|
|
#
|
|
create table t1 (ts timestamp);
|
|
set time_zone='UTC';
|
|
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'),
|
|
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'),
|
|
('2037-12-31 23:59:59'),('2038-01-01 00:00:00');
|
|
select * from t1;
|
|
delete from t1;
|
|
# MET time zone has range shifted by one hour
|
|
set time_zone='MET';
|
|
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'),
|
|
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'),
|
|
('2038-01-01 00:59:59'),('2038-01-01 01:00:00');
|
|
select * from t1;
|
|
delete from t1;
|
|
# same for +01:30 time zone
|
|
set time_zone='+01:30';
|
|
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'),
|
|
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'),
|
|
('2038-01-01 01:29:59'),('2038-01-01 01:30:00');
|
|
select * from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
#
|
|
# Test of show variables
|
|
#
|
|
show variables like 'time_zone';
|
|
set time_zone = default;
|
|
show variables like 'time_zone';
|
|
|
|
|
|
#
|
|
# Let us try some invalid time zone specifications
|
|
#
|
|
--error 1298
|
|
set time_zone= '0';
|
|
--error 1298
|
|
set time_zone= '0:0';
|
|
--error 1298
|
|
set time_zone= '-20:00';
|
|
--error 1298
|
|
set time_zone= '+20:00';
|
|
--error 1298
|
|
set time_zone= 'Some/Unknown/Time/Zone';
|
|
|
|
|
|
# Let us check that aliases for time zones work and they are
|
|
# case-insensitive
|
|
select convert_tz(now(),'UTC', 'Universal') = now();
|
|
select convert_tz(now(),'utc', 'UTC') = now();
|
|
|
|
|
|
#
|
|
# Let us test CONVERT_TZ function (may be func_time.test is better place).
|
|
#
|
|
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC');
|
|
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC');
|
|
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC');
|
|
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC');
|
|
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC');
|
|
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC');
|
|
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC');
|
|
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC');
|
|
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC');
|
|
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC');
|
|
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC');
|
|
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC');
|
|
select convert_tz('2038-01-01 00:59:59', 'MET', 'UTC');
|
|
select convert_tz('2038-01-01 01:00:00', 'MET', 'UTC');
|
|
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC');
|
|
|
|
# Let us test variable time zone argument
|
|
create table t1 (tz varchar(3));
|
|
insert into t1 (tz) values ('MET'), ('UTC');
|
|
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz;
|
|
drop table t1;
|
|
|
|
# Parameters to CONVERT_TZ() what should give NULL
|
|
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC');
|
|
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC');
|
|
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone');
|
|
select convert_tz('2003-12-31 04:00:00', 'MET', NULL);
|
|
select convert_tz( NULL, 'MET', 'UTC');
|
|
|
|
#
|
|
# Test for bug #4508 "CONVERT_TZ() function with new time zone as param
|
|
# crashes server." (Was caused by improperly worked mechanism of time zone
|
|
# dynamical loading).
|
|
#
|
|
create table t1 (ts timestamp);
|
|
set timestamp=1000000000;
|
|
insert into t1 (ts) values (now());
|
|
select convert_tz(ts, @@time_zone, 'Japan') from t1;
|
|
drop table t1;
|
|
|