[CONC-372] Fix str_to_TIME() parsing wrt performance. Created: 2018-11-08  Updated: 2021-02-01  Resolved: 2018-11-13

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: None
Fix Version/s: 3.0.8

Type: Bug Priority: Major
Reporter: Vladislav Vaintroub Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Problem/Incident
causes CONC-378 MYSQL_DATA_TRUNCATED not always retur... Closed

 Description   

currently, parsing str_to_TIME() is too complicated, and even embarassing in terms of performance

https://github.com/MariaDB/mariadb-connector-c/blob/6545b1d194d5fd037844f7a0d93604fb4757cf41/libmariadb/ma_stmt_codec.c#L199

Following calls inside it can and should be removed.
alloca, memcpy, memset, strchr (x4), sscanf



 Comments   
Comment by Vladislav Vaintroub [ 2018-11-09 ]

while testing , found additional bugs in current str_to_TIME()

Major :

  • "0000-00-00" after parsing becomes year 1970, should be 0
  • "0069-12-31" parses as year 1969, should be 69 (YYYY format)
    the above 2 make it impossible to parse anything from years 1 AD - 70 AD (and the fake MySQLish year 0)
  • "69-12-31" parses as year 1969, should be 2069

Minor /debatable , differences with server

  • fails to parse "10:15:01." as TIME (note the trailing dot)
  • parses "10000-01-01", which server dismisses as incorrect date ( year > 9999)
  • parses time >= 839:00:00 and time <= -839:00:00, which server does not do
  • parses incorrect datetime "1999-12-31 834:59:59.999999" is parses as datetime, with hour = 834
  • server allows trailing spaces after values, but nothing else, str_to_TIME() allows anything ,except trailing dot e.g "2000-01-01a"
  • does not parse some formats that server can, e.g "YYYYMMDD"

Server testing is done with SELECT TIME 'string' , SELECT DATE 'string', SELECT TIMESTAMP 'string' e.g

select DATETIME '1999-12-31 834:59:59.999999';

Generated at Thu Feb 08 03:04:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.