Skip to content
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

tidb reports syntax error while mysql does not #1127

Closed
eurekaka opened this issue Dec 16, 2020 · 4 comments · Fixed by #1255
Closed

tidb reports syntax error while mysql does not #1127

eurekaka opened this issue Dec 16, 2020 · 4 comments · Fixed by #1255
Assignees
Labels
severity/moderate type/bug Something isn't working

Comments

@eurekaka
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table t(a int);
-- SQL_1
SELECT t1.a AS a FROM (SELECT a FROM t) AS t1;
-- SQL_2
SELECT t1.a AS a FROM ((SELECT a FROM t) AS t1);
  1. What did you expect to see?

As MySQL, there should be no syntax error for SQL_1 and SQL_2.

  1. What did you see instead?

SQL_1 successes, while SQL_2 fails.

  1. What version of TiDB SQL Parser are you using?

3abb698

I tried to change the SetOprStmt1 in line 8021 back to SelectStmt, the above problem can be fixed, but there would be some test failures for set operations.

 8010 TableFactor:
 8011     TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt TableSampleOpt
 8012     {
 8013         tn := $1.(*ast.TableName)
 8014         tn.PartitionNames = $2.([]model.CIStr)
 8015         tn.IndexHints = $4.([]*ast.IndexHint)
 8016         if $5 != nil {
 8017             tn.TableSample = $5.(*ast.TableSample)
 8018         }
 8019         $$ = &ast.TableSource{Source: tn, AsName: $3.(model.CIStr)}
 8020     }
 8021 |   '(' SetOprStmt1 ')' TableAsNameOpt
 8022     {
 8023         if st, isSel := $2.(*ast.SelectStmt); isSel {
 8024             endOffset := parser.endOffset(&yyS[yypt-1])
 8025             parser.setLastSelectFieldText(st, endOffset)
 8026         }
 8027         $$ = &ast.TableSource{Source: $2.(ast.ResultSetNode), AsName: $4.(model.CIStr)}
 8028     }
 8029 |   '(' TableRefs ')'
 8030     {
 8031         $$ = $2
 8032     }
@eurekaka eurekaka added the type/bug Something isn't working label Dec 16, 2020
@xiongjiwei
Copy link
Contributor

MySQL 8.0 will return syntax error too

mysql> SELECT t1.a AS a FROM ((SELECT a FROM t) AS t1);
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 ')' at line 1
mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 8.0.22-0ubuntu0.20.04.3 |
+-------------------------+
1 row in set (0.00 sec)

@eurekaka
Copy link
Contributor Author

The current Restore() functions in parser may generate queries like SQL_2, which would be problematic then.

@xiongjiwei
Copy link
Contributor

The current Restore() functions in parser may generate queries like SQL_2, which would be problematic then.

can you please give some examples?

@xiongjiwei
Copy link
Contributor

xiongjiwei commented Dec 23, 2020

select * from ((select a from t) t1 join t t2); # invalid in tidb. valid in MySQL
SELECT * FROM ((SELECT a FROM t) t1);   # invalid both tidb and MySQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants