pingcap/tidb

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

Open

#40.201 aberto em 27 de dez. de 2022

Ver no GitHub
 (2 comments) (1 reaction) (0 assignees)Go (6.186 forks)batch import
component/parserhelp wantedsig/sql-infratype/enhancement

Métricas do repositório

Stars
 (40.090 stars)
Métricas de merge de PR
 (Mesclagem média 14d 4h) (346 fundiu PRs em 30d)

Description

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).

Guia do colaborador