New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fix bug for parsing builtin UTC_TIME/UTC_TIMESTAMP/CUR_TIME/CURRENT_TIME/CURRENT_TIMESTAMP #4306

Merged
merged 7 commits into from Aug 28, 2017

Conversation

Projects
None yet
3 participants
@spongedu
Contributor

spongedu commented Aug 23, 2017

The first bug:

In mysql: builtin function UTC_TIME,UTC_TIMESTAMP,CUR_TIME, CURRENT_TIMESTAMP, CURRENT_TIME accepts 0 or 1 parameter. In the latter case, the parameter must be unsigned int , or there would be an parse error. No such check was done in TiDB currently. TiDB may fail when optimizer infer types sometimes, and pass some other time(depends on whether the actual parameter can be cast to type 'int'), which is not expected. examples:
In Mysql

mysql> select utc_time(c_int) from t;
ERROR 1064 (42000): 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 'c_int) from t' at line 1
mysql> select utc_time(null) from t;
ERROR 1064 (42000): 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 'null) from t' at line 1
mysql> select utc_time(-1) from t;
ERROR 1064 (42000): 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 '-1) from t' at line 1
mysql> select utc_time(1.0) from t;
ERROR 1064 (42000): 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 '1.0) from t' at line 1
mysql> select utc_time("4") from t;
ERROR 1064 (42000): 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 '"4") from t' at line 1

In TiDB:

tidb> select utc_time(c_int) from t;
ERROR 1105 (HY000): cannot convert <nil>(type <nil>) to int64
tidb> select utc_time(null);
ERROR 1105 (HY000): cannot convert <nil>(type <nil>) to int64
tidb> select utc_time(-1);
ERROR 1105 (HY000): cannot convert <nil>(type <nil>) to int64
tidb> select utc_time(1.0);
Field   1:  `utc_time(1.0)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       TIME
Collation:  binary (63)
Length:     0
Max_length: 10
Decimals:   1
Flags:      BINARY 


+---------------+
| utc_time(1.0) |
+---------------+
| 16:03:43.3    |
+---------------+
1 row in set (0.01 sec)
tidb> select utc_time("1");
Field   1:  `utc_time("1")`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       TIME
Collation:  binary (63)
Length:     0
Max_length: 10
Decimals:   1
Flags:      BINARY 


+---------------+
| utc_time("1") |
+---------------+
| 16:04:13.4    |
+---------------+
1 row in set (0.00 sec)

The second bug:

Just like UTC_TIMESTAMP, UTC_TIME support 'No parameter, No brackets' from in mysql. Which is not supported in TiDB for now.

In Mysql

mysql> select utc_time;
Field   1:  `utc_time`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       TIME
Collation:  binary (63)
Length:     8
Max_length: 8
Decimals:   0
Flags:      NOT_NULL BINARY 

+----------+
| utc_time |
+----------+
| 15:58:54 |
+----------+
1 row in set (0.00 sec)

In TiDB:

tidb> select utc_time;
ERROR 1054 (42S22): Unknown column 'utc_time' in 'field list'

@spongedu spongedu changed the title from parser: fix bug for parsing builtin UTC_TIME/UTC_TIMESTAMP to parser: fix bug for parsing builtin UTC_TIME/UTC_TIMESTAMP/CUR_TIME/CURRENT_TIME/CURRENT_TIMESTAMP Aug 23, 2017

@zz-jason

This comment has been minimized.

Show comment
Hide comment
@zz-jason
Member

zz-jason commented Aug 24, 2017

Show outdated Hide outdated parser/parser.y
@spongedu

This comment has been minimized.

Show comment
Hide comment
@spongedu

spongedu Aug 24, 2017

Contributor

@breeswish Fix CUR_TIME related issue. PTAL.

Contributor

spongedu commented Aug 24, 2017

@breeswish Fix CUR_TIME related issue. PTAL.

@breeswish

This comment has been minimized.

Show comment
Hide comment
@breeswish

breeswish Aug 28, 2017

Member

LGTM

Member

breeswish commented Aug 28, 2017

LGTM

@breeswish breeswish added status/LGT2 and removed status/LGT1 labels Aug 28, 2017

@breeswish breeswish merged commit c27a3db into pingcap:master Aug 28, 2017

3 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

dbjoa added a commit to cloud-pi/tidb that referenced this pull request Aug 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment