Bug #60811 slow timezone functions

Submitted: 8 Apr 2011 23:41 Modified: 10 Apr 2011 9:29
Reporter: Steven Barre Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S5 (Performance)
Version:5.0.93, 5.5.12, 5.0.77-4.el5_5.4 OS:Any (RHEL 5.5, Mac OS X)
Assigned to: CPU Architecture:Any

[8 Apr 2011 23:41] Steven Barre
Description:
Functions involving timezones are much slower when using the SYSTEM time zone in MySQL as compared to any other time zone.

RPM mysql-server-5.0.77-4.el5_5.4
Kernel 2.6.18-194.17.4.el5

$cat /etc/sysconfig/clock

ZONE="US/Central"
UTC=false
ARC=false

mysql> SELECT @@global.time_zone, @@session.time_zone;                          +--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+

How to repeat:
mysql> SET time_zone = 'US/Central'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (0.57 sec)

mysql> SET time_zone = 'SYSTEM'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (0.90 sec)

Suggested fix:
A workaround is to use default-time-zone in the cnf file to set a zone instead of using SYSTEM.
[10 Apr 2011 9:29] Valeriy Kravchuk
Verified with current 5.0.93 from bzr on Mac OS X:

macbook-pro:5.0 openxs$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.93-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET time_zone = 'US/Central'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.01 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 | 
+-------------------------------------------------+
1 row in set (1.13 sec)

mysql> SET time_zone = 'US/Central'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 | 
+-------------------------------------------------+
1 row in set (1.13 sec)

mysql> SET time_zone = 'SYSTEM'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 | 
+-------------------------------------------------+
1 row in set (1.48 sec)

mysql> SET time_zone = 'SYSTEM'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 | 
+-------------------------------------------------+
1 row in set (1.45 sec)
[10 Apr 2011 9:32] Valeriy Kravchuk
MySQL 5.5 is also affected:

macbook-pro:5.5 openxs$ bin/mysql -uroot testReading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.12-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET time_zone = 'US/Central'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.03 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (1.12 sec)

mysql> SET time_zone = 'US/Central'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (1.11 sec)

mysql> SET time_zone = 'SYSTEM'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.01 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (1.43 sec)

mysql> SET time_zone = 'SYSTEM'; SELECT BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855));
Query OK, 0 rows affected (0.00 sec)

+-------------------------------------------------+
| BENCHMARK( 1000000, FROM_UNIXTIME( 1302301855)) |
+-------------------------------------------------+
|                                               0 |
+-------------------------------------------------+
1 row in set (1.47 sec)
[15 Aug 2020 10:10] Maxim Turkin
Looks like this bug also affects selects from table by timestamp column

mysql> SET time_zone = 'UTC';

mysql> select count(*) from `tablename` where `date` < '2020-08-15 00:00:00';
1 row in set (0.12 sec)

mysql> SET time_zone = 'SYSTEM';

mysql> select count(*) from `tablename` where `date` < '2020-08-15 00:00:00';
1 row in set (0.33 sec)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.