pingcap / pingcap/tidb

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

Open
#40,201 2 comments 1 reaction 0 assignees View on GitHub
component/parser help wanted sig/sql-infra type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

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](https://dev.mysql.com/doc/refman/5.7/en/select.html):

> 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`](https://github.com/pingcap/tidb/blob/fdf335e3e5217a6c625ee3908e1a95f60791060b/parser/parser.y#L8646) 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](https://dev.mysql.com/doc/refman/8.0/en/select.html), we could also consider supporting it as well(nice to have).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.