tidb-challenge-program / bug-hunting-issue

Bug hunting issues.
3 stars 0 forks source link

P1-[4.0 bug hunting]-[SQL Plan Management]-CREATE TABLE with generated column unexpectedly causes a syntax error #52

Open mrigger opened 4 years ago

mrigger commented 4 years ago

Consider the following statement:

CREATE TABLE t0(c0 BINARY AS (CAST(0 AS BINARY))); -- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 30 near "binary)"

Unexpectedly, it results in a syntax error:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.25-TiDB- TiDB Server (Apache License 2.0), MySQL 5.7 compatible

Copyright (c) 2000, 2020, 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> CREATE TABLE t0(c0 BINARY AS (CAST(0 AS BINARY)));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 30 near "binary)" 

Creating tables with other casts work as expected. For example:

CREATE TABLE t0(c0 BINARY AS (CAST(0 AS SIGNED))); -- ok

Using a cast outside the CREATE TABLE also works as expected:

SELECT CAST(0 AS BINARY); -- 0x30

I found this based on the latest master commit b6fcc157442894f048c1cc65cfcc7776e9ed1a72, and can also reproduce it on the 4.0 RC.

shuke987 commented 4 years ago

/bug P2