Skip to content

Commit 09ba29e

Browse files
WL#1264 "Per-thread time zone support infrastructure".
Added basic per-thread time zone functionality (based on public domain elsie-code). Now user can select current time zone (from the list of time zones described in system tables). All NOW-like functions honor this time zone, values of TIMESTAMP type are interpreted as values in this time zone, so now our TIMESTAMP type behaves similar to Oracle's TIMESTAMP WITH LOCAL TIME ZONE (or proper PostgresSQL type). WL#1266 "CONVERT_TZ() - basic time with time zone conversion function". Fixed problems described in Bug #2336 (Different number of warnings when inserting bad datetime as string or as number). This required reworking of datetime realted warning hadling (they now generated at Field object level not in conversion functions). Optimization: Now Field class descendants use table->in_use member instead of current_thd macro.
1 parent 48a47a0 commit 09ba29e

81 files changed

Lines changed: 5140 additions & 573 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bzrignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,6 @@ ndb/src/common/mgmcommon/printConfig/*.d
780780
ndb/src/mgmclient/test_cpcd/*.d
781781
*.d
782782
libmysqld/examples/client_test.c
783+
sql/test_time
784+
sql/mysql_tzinfo_to_sql
785+
libmysqld/tztime.cc

include/my_global.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,14 @@ do { doubleget_union _tmp; \
11011101

11021102
#endif /* sint2korr */
11031103

1104+
/*
1105+
Macro for reading 32-bit integer from network byte order (big-endian)
1106+
from unaligned memory location.
1107+
*/
1108+
#define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\
1109+
(((uint32) ((uchar) (A)[2])) << 8) |\
1110+
(((uint32) ((uchar) (A)[1])) << 16) |\
1111+
(((uint32) ((uchar) (A)[0])) << 24))
11041112
/*
11051113
Define-funktions for reading and storing in machine format from/to
11061114
short/long to/from some place in memory V should be a (not

include/mysqld_error.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,6 @@
314314
#define ER_UNSUPPORTED_PS 1295
315315
#define ER_GET_ERRMSG 1296
316316
#define ER_GET_TEMPORARY_ERRMSG 1297
317-
#define ER_ERROR_MESSAGES 298
317+
#define ER_UNKNOWN_TIME_ZONE 1298
318+
#define ER_WARN_INVALID_TIMESTAMP 1299
319+
#define ER_ERROR_MESSAGES 300

libmysqld/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
5656
sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
5757
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
5858
unireg.cc uniques.cc stacktrace.c sql_union.cc hash_filo.cc \
59-
spatial.cc gstream.cc sql_help.cc
59+
spatial.cc gstream.cc sql_help.cc tztime.cc
6060

6161
libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources)
6262
libmysqld_a_SOURCES=

libmysqld/lib_sql.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
356356
int fake_argc = 1;
357357
char *fake_argv[] = { (char *)"", 0 };
358358
const char *fake_groups[] = { "server", "embedded", 0 };
359+
my_bool acl_error;
359360
if (argc)
360361
{
361362
argcp= &argc;
@@ -397,16 +398,17 @@ int init_embedded_server(int argc, char **argv, char **groups)
397398

398399
error_handler_hook = my_message_sql;
399400

401+
acl_error= 0;
400402
#ifndef NO_EMBEDDED_ACCESS_CHECKS
401-
if (acl_init((THD *)0, opt_noacl))
403+
if (!(acl_error= acl_init((THD *)0, opt_noacl)) &&
404+
!opt_noacl)
405+
(void) grant_init((THD *)0);
406+
#endif
407+
if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
402408
{
403409
mysql_server_end();
404410
return 1;
405411
}
406-
if (!opt_noacl)
407-
(void) grant_init((THD *)0);
408-
409-
#endif
410412

411413
init_max_user_conn();
412414
init_update_queries();

mysql-test/r/connect.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ help_relation
99
help_topic
1010
host
1111
tables_priv
12+
time_zone
13+
time_zone_leap_second
14+
time_zone_name
15+
time_zone_transition
16+
time_zone_transition_type
1217
user
1318
show tables;
1419
Tables_in_test
@@ -25,6 +30,11 @@ help_relation
2530
help_topic
2631
host
2732
tables_priv
33+
time_zone
34+
time_zone_leap_second
35+
time_zone_name
36+
time_zone_transition
37+
time_zone_transition_type
2838
user
2939
show tables;
3040
Tables_in_test
@@ -42,6 +52,11 @@ help_relation
4252
help_topic
4353
host
4454
tables_priv
55+
time_zone
56+
time_zone_leap_second
57+
time_zone_name
58+
time_zone_transition
59+
time_zone_transition_type
4560
user
4661
show tables;
4762
Tables_in_test

mysql-test/r/date_formats.result

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ date format str_to_date
303303
2003-01-02 10:11:12 %Y-%m-%d %h:%i:%S 2003-01-02 10:11:12
304304
03-01-02 10:11:12 PM %Y-%m-%d %h:%i:%S %p 0003-01-02 22:11:12
305305
Warnings:
306-
Note 1292 Truncated incorrect string value: '10:20:10AM'
306+
Warning 1292 Truncated incorrect datetime value: '10:20:10AM'
307307
select date,format,concat(str_to_date(date, format),'') as con from t1;
308308
date format con
309309
10:20:10AM %h:%i:%s 0000-00-00 10:20:10
310310
2003-01-02 10:11:12 %Y-%m-%d %h:%i:%S 2003-01-02 10:11:12
311311
03-01-02 10:11:12 PM %Y-%m-%d %h:%i:%S %p 0003-01-02 22:11:12
312312
Warnings:
313-
Note 1292 Truncated incorrect string value: '10:20:10AM'
313+
Warning 1292 Truncated incorrect datetime value: '10:20:10AM'
314314
drop table t1;
315315
select get_format(DATE, 'USA') as a;
316316
a
@@ -374,21 +374,21 @@ str_to_date("02 10", "%d %f") as f6;
374374
f1 f2 f3 f4 f5 f6
375375
2003-01-02 10:11:12.001200 2003-01-02 10:11:12 2003-01-02 58:11:12 58:11:12 48:00:00.100000
376376
Warnings:
377-
Note 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012'
377+
Warning 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012'
378378
drop table t1, t2;
379379
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
380380
addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
381381
microsecond("1997-12-31 23:59:59.01XXXX") as f3;
382382
f1 f2 f3
383383
2003-01-02 10:11:12.001200 -25:01:00.110000 10000
384384
Warnings:
385-
Note 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD'
386-
Note 1292 Truncated incorrect time value: '-01:01:01.01 GG'
387-
Note 1292 Truncated incorrect datetime value: '1997-12-31 23:59:59.01XXXX'
385+
Warning 1292 Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD'
386+
Warning 1292 Truncated incorrect time value: '-01:01:01.01 GGG'
387+
Warning 1292 Truncated incorrect time value: '1997-12-31 23:59:59.01XXXX'
388388
select str_to_date("2003-04-05 g", "%Y-%m-%d") as f1,
389389
str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
390390
f1 f2
391391
2003-04-05 2003-04-05 10:11:12.101010
392392
Warnings:
393-
Note 1292 Truncated incorrect date value: '2003-04-05 g'
394-
Note 1292 Truncated incorrect datetime value: '2003-04-05 10:11:12.101010234567'
393+
Warning 1292 Truncated incorrect date value: '2003-04-05 g'
394+
Warning 1292 Truncated incorrect datetime value: '2003-04-05 10:11:12.101010234567'

mysql-test/r/func_sapdb.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ timestamp("2001-12-01", "01:01:01.999999")
119119
select timestamp("2001-13-01", "01:01:01.000001");
120120
timestamp("2001-13-01", "01:01:01.000001")
121121
NULL
122+
Warnings:
123+
Warning 1292 Truncated incorrect datetime value: '2001-13-01'
122124
select timestamp("2001-12-01", "25:01:01");
123125
timestamp("2001-12-01", "25:01:01")
124126
2001-12-02 01:01:01
@@ -137,12 +139,16 @@ date("1997-12-31 23:59:59.000001")
137139
select date("1997-13-31 23:59:59.000001");
138140
date("1997-13-31 23:59:59.000001")
139141
NULL
142+
Warnings:
143+
Warning 1292 Truncated incorrect datetime value: '1997-13-31 23:59:59.000001'
140144
select time("1997-12-31 23:59:59.000001");
141145
time("1997-12-31 23:59:59.000001")
142146
23:59:59.000001
143147
select time("1997-12-31 25:59:59.000001");
144148
time("1997-12-31 25:59:59.000001")
145149
NULL
150+
Warnings:
151+
Warning 1292 Truncated incorrect time value: '1997-12-31 25:59:59.000001'
146152
select microsecond("1997-12-31 23:59:59.000001");
147153
microsecond("1997-12-31 23:59:59.000001")
148154
1

mysql-test/r/func_time.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,13 @@ INSERT INTO t1 VALUES ('');
411411
SELECT month(updated) from t1;
412412
month(updated)
413413
NULL
414+
Warnings:
415+
Warning 1292 Truncated incorrect datetime value: ''
414416
SELECT year(updated) from t1;
415417
year(updated)
416418
NULL
419+
Warnings:
420+
Warning 1292 Truncated incorrect datetime value: ''
417421
drop table t1;
418422
create table t1 (d date, dt datetime, t timestamp, c char(10));
419423
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
@@ -536,6 +540,8 @@ last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
536540
last_day('2001-02-12');
537541
f1 f2 f3 f4 f5 last_day(NULL) last_day('2001-02-12')
538542
2000-02-29 2002-12-31 NULL 2003-04-30 2001-01-31 NULL 2001-02-28
543+
Warnings:
544+
Warning 1292 Truncated incorrect datetime value: '2003-03-32'
539545
create table t1 select last_day('2000-02-05') as a,
540546
from_days(to_days("960101")) as b;
541547
describe t1;

mysql-test/r/rpl_timezone.result

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
stop slave;
2+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
3+
reset master;
4+
reset slave;
5+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
6+
start slave;
7+
create table t1 (t timestamp);
8+
create table t2 (t char(32));
9+
select @@time_zone;
10+
@@time_zone
11+
Europe/Moscow
12+
set time_zone='UTC';
13+
insert into t1 values ('20040101000000'), ('20040611093902');
14+
select * from t1;
15+
t
16+
2004-01-01 00:00:00
17+
2004-06-11 09:39:02
18+
select * from t1;
19+
t
20+
2004-01-01 03:00:00
21+
2004-06-11 13:39:02
22+
delete from t1;
23+
set time_zone='Europe/Moscow';
24+
insert into t1 values ('20040101000000'), ('20040611093902');
25+
select * from t1;
26+
t
27+
2004-01-01 00:00:00
28+
2004-06-11 09:39:02
29+
select * from t1;
30+
t
31+
2004-01-01 00:00:00
32+
2004-06-11 09:39:02
33+
show binlog events;
34+
Log_name Pos Event_type Server_id Orig_log_pos Info
35+
master-bin.000001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3
36+
master-bin.000001 79 Query 1 79 use `test`; create table t1 (t timestamp)
37+
master-bin.000001 143 Query 1 143 use `test`; create table t2 (t char(32))
38+
master-bin.000001 206 Query 1 206 use `test`; SET ONE_SHOT TIME_ZONE='UTC'
39+
master-bin.000001 269 Query 1 269 use `test`; insert into t1 values ('20040101000000'), ('20040611093902')
40+
master-bin.000001 364 Query 1 364 use `test`; delete from t1
41+
master-bin.000001 413 Query 1 413 use `test`; insert into t1 values ('20040101000000'), ('20040611093902')
42+
set time_zone='MET';
43+
insert into t2 (select t from t1);
44+
select * from t1;
45+
t
46+
2003-12-31 22:00:00
47+
2004-06-11 07:39:02
48+
select * from t2;
49+
t
50+
2003-12-31 22:00:00
51+
2004-06-11 07:39:02
52+
delete from t2;
53+
set timestamp=1000072000;
54+
insert into t2 values (current_timestamp), (current_date), (current_time);
55+
set timestamp=1000072000;
56+
select current_timestamp, current_date, current_time;
57+
current_timestamp current_date current_time
58+
2001-09-10 01:46:40 2001-09-10 01:46:40
59+
select * from t2;
60+
t
61+
2001-09-09 23:46:40
62+
2001-09-09
63+
23:46:40
64+
delete from t2;
65+
insert into t2 values (from_unixtime(1000000000)),
66+
(unix_timestamp('2001-09-09 03:46:40'));
67+
select * from t2;
68+
t
69+
2001-09-09 03:46:40
70+
1000000000
71+
select * from t2;
72+
t
73+
2001-09-09 03:46:40
74+
1000000000
75+
set global time_zone='MET';
76+
ERROR HY000: Binary logging and replication forbid changing of the global server time zone
77+
drop table t1, t2;

0 commit comments

Comments
 (0)