[MDEV-9175] [PATCH] Query parser tansforms MICROSECOND into SECOND_FRAC, which does not work Created: 2015-11-24  Updated: 2016-02-06  Resolved: 2016-02-06

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Temporal Types
Affects Version/s: 5.3.13, 5.5, 10.0, 10.1
Fix Version/s: 5.5.48, 10.0.24, 10.1.12

Type: Bug Priority: Major
Reporter: Jaime Crespo Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: upstream

Sprint: 5.5.48-0

 Description   

This works:

MariaDB LABS localhost heartbeat_p > SELECT CASE WHEN file like 'db1052%' THEN 's1' WHEN file like 'db1024%' THEN 's2' WHEN file like 'db1038%' THEN 's3' WHEN file like 'db1040%' THEN 's4' WHEN file like 'db1058%' THEN 's5' WHEN file like 'db1023%' THEN 's6' WHEN file like 'db1033%' THEN 's7' ELSE 'unknown' END as `shard`, TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6)) AS `lag` FROM heartbeat.heartbeat;
+-------+-------+
| shard | lag   |
+-------+-------+
| s6    | 18588 |
| s2    | 18738 |
| s7    | 18798 |
| s3    | 18788 |
| s4    | 18568 |
| s1    | 18928 |
| s5    | 19068 |
+-------+-------+
7 rows in set (0.00 sec)

This doesn't:

MariaDB LABS localhost heartbeat_p > CREATE VIEW `heartbeat` AS SELECT CASE WHEN file like 'db1052%' THEN 's1' WHEN file like 'db1024%' THEN 's2' WHEN file like 'db1038%' THEN 's3' WHEN file like 'db1040%' THEN 's4' WHEN file like 'db1058%' THEN 's5' WHEN file like 'db1023%' THEN 's6' WHEN file like 'db1033%' THEN 's7' ELSE 'unknown' END as `shard`, TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6)) AS `lag` FROM heartbeat.heartbeat;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB LABS localhost heartbeat_p > SELECT * FROM heartbeat;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SECOND_FRAC,`heartbeat`.`heartbeat`.`ts`,utc_timestamp()) AS `lag` from `heartbe' at line 1

The reason why:

MariaDB LABS localhost heartbeat_p > EXPLAIN EXTENDED SELECT CASE WHEN file like 'db1052%' THEN 's1' WHEN file like 'db1024%' THEN 's2' WHEN file like 'db1038%' THEN 's3' WHEN file like 'db1040%' THEN 's4' WHEN file like 'db1058%' THEN 's5' WHEN file like 'db1023%' THEN 's6' WHEN file like 'db1033%' THEN 's7' ELSE 'unknown' END as `shard`, TIMESTAMPDIFF(MICROSECOND,ts,UTC_TIMESTAMP(6)) AS `lag` FROM heartbeat.heartbeat\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: heartbeat
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 7
     filtered: 100.00
        Extra: 
1 row in set, 1 warning (0.00 sec)
 
MariaDB LABS localhost heartbeat_p > SHOW WARNINGS\G
*************************** 1. row ***************************
  Level: Note
   Code: 1003
Message: select (case when (`heartbeat`.`heartbeat`.`file` like 'db1052%') then 's1' when (`heartbeat`.`heartbeat`.`file` like 'db1024%') then 's2' when (`heartbeat`.`heartbeat`.`file` like 'db1038%') then 's3' when (`heartbeat`.`heartbeat`.`file` like 'db1040%') then 's4' when (`heartbeat`.`heartbeat`.`file` like 'db1058%') then 's5' when (`heartbeat`.`heartbeat`.`file` like 'db1023%') then 's6' when (`heartbeat`.`heartbeat`.`file` like 'db1033%') then 's7' else 'unknown' end) AS `shard`,timestampdiff(SECOND_FRAC,`heartbeat`.`heartbeat`.`ts`,utc_timestamp()) AS `lag` from `heartbeat`.`heartbeat`
1 row in set (0.00 sec)

Please note the the SECOND_FRAC, which shoudln't be there (it is deprecated).



 Comments   
Comment by Elena Stepanova [ 2015-12-25 ]

Thanks for the report.
MySQL 5.6/5.7 are also affected. When it is the case, our normal routine includes informing MySQL (reporting the bug at bugs.mysql.com).
jcrespo, are you willing to do it, or should we do it on your behalf?

Test case

select TIMESTAMPDIFF(MICROSECOND,'2000-01-01 00:00:00',UTC_TIMESTAMP(6));
explain extended
select TIMESTAMPDIFF(MICROSECOND,'2000-01-01 00:00:00',UTC_TIMESTAMP(6));
 
--let $datadir= `select @@datadir`
create view v1 as select TIMESTAMPDIFF(MICROSECOND,'2000-01-01 00:00:00',UTC_TIMESTAMP(6));
--cat_file $datadir/test/v1.frm
 
select * from v1;
drop view v1;

mysqltest: At line 9: query 'select * from v1' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SECOND_FRAC,'2000-01-01 00:00:00',utc_timestamp(6)) AS `Name_exp_1`' at line 1

Comment by Jaime Crespo [ 2015-12-26 ]

5 year-old bug: http://bugs.mysql.com/bug.php?id=60628

Comment by Jaime Crespo [ 2015-12-26 ]

I've created a patch here: https://github.com/mysql/mysql-server/pull/43

Comment by Elena Stepanova [ 2015-12-27 ]

Thanks!

Generated at Thu Feb 08 07:32:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.