[MDEV-30854] mariadb-tzinfo-to-sql creates sql_mode dependant statements Created: 2023-03-15  Updated: 2023-04-18  Resolved: 2023-04-18

Status: Closed
Project: MariaDB Server
Component/s: Time zones
Affects Version/s: 10.6, 10.11
Fix Version/s: 11.1.1, 10.11.3, 11.0.2, 10.6.13, 10.8.8, 10.9.6, 10.10.4

Type: Bug Priority: Minor
Reporter: Christian Roser Assignee: Daniel Black
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-18778 mysql_tzinfo_to_sql does not work cor... Closed
relates to MDEV-28263 mariadb-tzinfo-to-sql binlog, embedde... Closed
relates to MDEV-28782 mariadb-tzinfo-to-sql to work in boot... Closed

 Description   

Hi,

it looks like mariadb-tzinfo-to-sql generates some sql statements that only run under certain conditions:

empty sql_mode, working fine:

mysql@host[~](test)> mysql -BN -e "set @@global.sql_mode = ''"
mysql@host[~](test)> mariadb-tzinfo-to-sql /usr/share/zoneinfo/ | mysql mysql
mysql@host[~](test)> 

mysql@host[~](test)> mysql -BN -e "set @@global.sql_mode = 'ansi_quotes'"
mysql@host[~](test)> mariadb-tzinfo-to-sql /usr/share/zoneinfo/ | mysql -f mysql
ERROR 1054 (42S22) at line 4: Unknown column 'select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'' in 'field list'
ERROR 1054 (42S22) at line 6: Unknown column 'select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'' in 'field list'
ERROR 1054 (42S22) at line 8: Unknown column 'select ENGINE into @time_zone_transition_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_transition'' in 'field list'
ERROR 1054 (42S22) at line 10: Unknown column 'select ENGINE into @time_zone_transition_type_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_transition_type'' in 'field list'

statements that cause the issue have double quotes in line 5,7,9,11

1
mysql@host[~](test)> mariadb-tzinfo-to-sql /usr/share/zoneinfo/ | head -12
2
set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on');
3
SET STATEMENT SQL_MODE='' FOR SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt  FROM   (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION    FROM information_schema.TABLES    WHERE TABLE_SCHEMA=DATABASE()      AND TABLE_NAME IN ('time_zone',                         'time_zone_name',                         'time_zone_transition',                         'time_zone_transition_type',                         'time_zone_leap_second')      AND ENGINE in ('MyISAM',                     'Aria')) AS o ORDER BY OPTION DESC;
4
set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode');
5
execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0');
6
execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0');
7
execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0');
8
execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone_name ENGINE=InnoDB', 'do 0');
9
execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_transition_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_transition'", 'do 0');
10
execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone_transition ENGINE=InnoDB', 'do 0');
11
execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_transition_type_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_transition_type'", 'do 0');
12
execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone_transition_type ENGINE=InnoDB', 'do 0');
13
TRUNCATE TABLE time_zone;



 Comments   
Comment by Daniel Lenski [ 2023-04-14 ]

Closely related to MDEV-18778 , MDEV-28263, and MDEV-28782.

The common feature: there's a lack of testing of whether or not the generated timezone.sql actually works in different build and execution environments.

Comment by Daniel Lenski [ 2023-04-14 ]

This bug (using " in the generated timezone SQL) was introduced by danblack in

https://github.com/MariaDB/server/commit/13e77930e615f05cc74d408110e887b00e1abcc9#diff-a333d4ebb2d73b6361ef7dfebc86d883f7e19853b4a9eb85984b039058fae47cR2431-R2435

Comment by Daniel Lenski [ 2023-04-14 ]

PR to fix this issue: https://github.com/MariaDB/server/pull/2604

Comment by Daniel Black [ 2023-04-18 ]

thanks dlenski!

Generated at Thu Feb 08 10:19:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.