pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.41k stars 489 forks source link

parsing error when associated query contains subquery #1258

Open zhaoxugang opened 3 years ago

zhaoxugang commented 3 years ago

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 table1 ( id int(0) DEFAULT NULL, name varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE table2 ( id int(0) DEFAULT NULL, name varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

insert into table1(id ,name) values(1,'a'); insert into table2(id ,name) values(1,'a');

select t1.id as i1,t2.id as i2,t3.id as i3 from (select tt.id,tt.name from (select id,name from table1) tt) as t1 LEFT JOIN table1 t2 on t1.name = t2.name LEFT JOIN table2 t3 on t1.name = t3.name;

select * from temp_v;

  1. What did you expect to see?

------+------+------+ | i1 | i2 | i3 | +------+------+------+ | 1 | 1 | 1 | +------+------+------+

  1. What did you see instead?

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 103 near "AS t1 LEFT JOIN test.table1 AS t2 ON t1.name=t2.name) LEFT JOIN test.table2 AS t3 ON t1.name=t3.name"

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