Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: compatibility enhancement for SELECT ... INTO syntax #40201

Open
bb7133 opened this issue Dec 27, 2022 · 2 comments
Open

parser: compatibility enhancement for SELECT ... INTO syntax #40201

bb7133 opened this issue Dec 27, 2022 · 2 comments
Labels
component/parser help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@bb7133
Copy link
Member

bb7133 commented Dec 27, 2022

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:

SelectStmt:

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).
@bb7133 bb7133 added type/enhancement The issue or PR belongs to an enhancement. component/parser sig/sql-infra SIG: SQL Infra help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Dec 27, 2022
@mjonss
Copy link
Contributor

mjonss commented Dec 28, 2022

@bb7133 do you only mean that the parser should correctly parse this, and then we can fail with a better error message?Since I don't think we should fully support into outfile since TiDB is a cluster and you may not be aware of which TiDB SQL node you were using.

@bb7133
Copy link
Member Author

bb7133 commented Jan 18, 2023

@mjonss I think we should support INTO in different positions(just like MySQL) without any other funcational enhancement, since some 3rd-party tools use it in this way.

Since I don't think we should fully support into outfile

Yes, I agree with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/parser help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants