parser: compatibility enhancement for `SELECT ... INTO` syntax
#40,201 创建于 2022年12月27日
仓库指标
- Star
- (40,090 star)
- PR 合并指标
- (平均合并 14天 4小时) (30 天内合并 346 个 PR)
描述
Enhancement
Now TiDB does not support the following SELECT ... INTO syntax:
tidb> select * into outfile 'abc' from test.t;
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 32 near "from test.t"
In which INTO clause appears before FROM clause, as described in MySQL manual:
SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS] select_expr [, select_expr] ... [into_option] [FROM table_references [PARTITION partition_list]] [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [into_option] [FOR UPDATE | LOCK IN SHARE MODE]
into_option: { INTO OUTFILE 'file_name' [CHARACTER SET charset_name] export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name] ... }
...
The INTO clause, if present, can appear in any position indicated by the syntax description, but within a given statement can appear only once, not in multiple positions...
To improve the compatibility, we need to update parser.y file and try to update the declaration of SelectStmt:
https://github.com/pingcap/tidb/blob/fdf335e3e5217a6c625ee3908e1a95f60791060b/parser/parser.y#L8646
Some tips:
- Please notice that the change might be trivial or non-trivial because the parsing code of TiDB is not the same as MySQL.
- In MySQL 8.0, the
INTOclause is allowed to appear afterFOR UPDATEclause, we could also consider supporting it as well(nice to have).