pingcap/tidb

parser: compatibility enhancement for `SELECT ... INTO` syntax

Open

#40,201 opened on 2022年12月27日

GitHub で見る
 (2 comments) (1 reaction) (0 assignees)Go (6,186 forks)batch import
component/parserhelp wantedsig/sql-infratype/enhancement

Repository metrics

Stars
 (40,090 stars)
PR merge metrics
 (平均マージ 14d 4h) (30d で 346 merged PRs)

説明

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 INTO clause is allowed to appear after FOR UPDATE clause, we could also consider supporting it as well(nice to have).

コントリビューターガイド