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

ddl, planner, config: report unsupported for create/drop temporary table #14452

Closed

Conversation

ffutop
Copy link
Contributor

@ffutop ffutop commented Jan 11, 2020

What problem does this PR solve?

Fix pingcap/parser#609
report unsupported error.

What is changed and how it works?

# Turn off option ignore-ddl-temporary-keyword
mysql> CREATE TEMPORARY TABLE t (a INT);
ERROR 8200 (HY000): 'CREATE TEMPORARY TABLE' is currently unsupported
mysql> DROP TEMPORARY TABLE t;
ERROR 8200 (HY000): 'DROP TEMPORARY TABLE' is currently unsupported
mysql> CREATE TABLE t (a INT);
Query OK, 0 rows affected (0.01 sec)

mysql> DROP TABLE t;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TEMPORARY SEQUENCE seq START WITH 100;
ERROR 8200 (HY000): 'CREATE TEMPORARY SEQUENCE' is currently unsupported
mysql> DROP TEMPORARY SEQUENCE seq;
ERROR 8200 (HY000): 'DROP TEMPORARY SEQUENCE' is currently unsupported
mysql> CREATE SEQUENCE seq START WITH 100;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP SEQUENCE seq;
Query OK, 0 rows affected (0.00 sec)
# Turn on option ignore-ddl-temporary-keyword (default)
mysql> CREATE TEMPORARY TABLE t (a INT);
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

mysql> DROP TEMPORARY TABLE t;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> SHOW TABLES;
Empty set (0.00 sec)

mysql> CREATE TEMPORARY SEQUENCE seq START WITH 100;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SHOW CREATE TABLE seq\G
*************************** 1. row ***************************
       Table: seq
Create Table: CREATE TABLE `seq` (

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

mysql> DROP TEMPORARY SEQUENCE seq;
Query OK, 0 rows affected, 1 warning (0.00 sec)

Check List

Tests

  • Unit test

@ffutop ffutop requested a review from a team as a code owner January 11, 2020 11:36
@sre-bot sre-bot added the contribution This PR is from a community contributor. label Jan 11, 2020
@ghost ghost requested review from alivxxx and winoros and removed request for a team January 11, 2020 11:36
@wwar
Copy link

wwar commented Jan 11, 2020

May I suggest an error message similar to "CREATE TEMPORARY TABLE is currently unsupported".

The message "Unsupported temporary table" is ambiguous; it could be interpreted as temporary tables are supported, but this particular one is not.

@bb7133 bb7133 added the type/enhancement The issue or PR belongs to an enhancement. label Jan 12, 2020
@bb7133
Copy link
Member

bb7133 commented Jan 12, 2020

Hi @ffutop , thanks for your contribution!

@bb7133
Copy link
Member

bb7133 commented Jan 14, 2020

The implementation looks fine for me. However, changing such behaviors means a potential breakdown for TiDB users. For example, many users switched their databases from MySQL to TiDB may have their scripts with TEMPORARY TABLE, that's why TiDB ignores this keyword by design.

Would you please add a configuration option(naming 'compatible mode', for example)? You can check the implementation of https://github.com/pingcap/tidb/blob/master/config/config.toml.example#L61 as a reference.

@wwar
Copy link

wwar commented Jan 14, 2020

@bb7133 I think the behavior proposed here is an improvement since the case where the keyword TEMPORARY can be ignored is quite narrow:

  • The script would have to be single-threaded, and cleanup after itself to prevent name collisions.
  • There are also potential leakage scenarios, since the script may not have assumed that another user could read the data, or assume concurrent usage.
  • TEMPORARY tables also have a weird behavior where they can have the same name as a regular table, and reading from the temp table will take precedence.

@ffutop
Copy link
Contributor Author

ffutop commented Jan 14, 2020

@bb7133 I'd like to take your advice. I'm not sure is it ok naming new option ignore-ddl-temporary-keywords

Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

planner/core/preprocess_test.go Outdated Show resolved Hide resolved
planner/core/preprocess_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tangenta tangenta added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 14, 2020
@bb7133
Copy link
Member

bb7133 commented Jan 15, 2020

@bb7133 I'd like to take your advice. I'm not sure is it ok naming new option ignore-ddl-temporary-keywords

How do you think about this option? @tangenta @kennytm

@kennytm
Copy link
Contributor

kennytm commented Jan 15, 2020

  1. Please also handle CREATE TEMPORARY SEQUENCE and DROP TEMPORARY SEQUENCE (if CREATE SEQUENCE already works)
  2. Do we care about the CREATE TEMPORARY TABLES privilege
  3. Having an option is fine. But are we going to keep this option for a long time (e.g. what would we do after we've actually implemented TEMPORARY TABLE)?

@ffutop
Copy link
Contributor Author

ffutop commented Jan 15, 2020

@kennytm I can not find any mysql docs that introduce CREATE/DROP SEQUENCE.
And I tried following commands based on parser.y

CREATE SEQUENCE create a new table. And DROP SEQUENCE not works.

tidb> CREATE SEQUENCE seq;
Query OK, 0 rows affected (0.00 sec)

tidb> SHOW TABLES;
+----------------+
| Tables_in_test |
+----------------+
| seq            |
+----------------+
1 row in set (0.00 sec)

tidb> DROP SEQUENCE seq;
Query OK, 0 rows affected (0.00 sec)

tidb> SHOW TABLES;
+----------------+
| Tables_in_test |
+----------------+
| seq            |
+----------------+
1 row in set (0.00 sec)

tidb> DROP TABLE seq;
Query OK, 0 rows affected (0.01 sec)

tidb> SHOW TABLES;
Empty set (0.00 sec)

@kennytm
Copy link
Contributor

kennytm commented Jan 15, 2020

@ffutop You could refer to MariaDB's documentation https://mariadb.com/kb/en/create-sequence/ for the syntax (this mostly equivalent to the "sequence generator" feature in ANSI SQL:2003, also shared by PostgreSQL, Oracle Database, Microsoft Transact-SQL, IBM DB2, and probably many other RDBMS).

Anyway, my comment is that CREATE TEMPORARY SEQUENCE seq ... should have the same treatment as CREATE TEMPORARY TABLE tbl (...) regarding the "TEMPORARY" keyword. Since this feature was recently implemented I wasn't sure if it already works on latest TiDB, and it seems to be working.

@bb7133
Copy link
Member

bb7133 commented Jan 16, 2020

I can not find any mysql docs that introduce CREATE/DROP SEQUENCE.

The support of SEQUENCE is in-progress(although it is not supported by MySQL, as what you find out already).

@ffutop ffutop changed the title Report unsupported for create/drop temporary table ddl: report unsupported for create/drop temporary table Jan 16, 2020
@alivxxx alivxxx removed their request for review January 19, 2020 03:44
…d-for-temporary-table

# Conflicts:
#	config/config.toml.example
#	config/config_test.go
@ffutop
Copy link
Contributor Author

ffutop commented Jan 19, 2020

@bb7133 PTAL

@zz-jason zz-jason changed the title ddl: report unsupported for create/drop temporary table ddl, planner, config: report unsupported for create/drop temporary table Mar 2, 2020
@zimulala zimulala added sig/sql-infra SIG: SQL Infra and removed component/DDL1 labels Mar 4, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 9, 2020

@ffutop, please update your pull request.

…for-temporary-table

# Conflicts:
#	config/config.go
#	config/config.toml.example
#	config/config_test.go
#	planner/core/preprocess.go
#	planner/core/preprocess_test.go
@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #14452 into master will not change coverage by %.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #14452   +/-   ##
===========================================
  Coverage   80.6165%   80.6165%           
===========================================
  Files           505        505           
  Lines        136142     136142           
===========================================
  Hits         109753     109753           
  Misses        17892      17892           
  Partials       8497       8497           

# ignore-ddl-temporary-keyword is used to make ddl TEMPORARY keyword compatible with previous version TiDB.
# turn on this option, 'TEMPORARY' will ignored by TiDB as previous. Please make sure you fully understand the negative impact.
# turn off this option, use 'CREATE/DROP TEMPORARY TABLE' or 'CREATE/DROP TEMPORARY SEQUENCE' will reported an error.
ignore-ddl-temporary-keyword = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider an older version of TiDB, which do not have this config item in the config file, updated to this version. The default value of this item is false, then there is chance that the application may failed to run on the newer version TiDB.

BTW, it makes user confused when we using double negation. How about renaming it to reserve-ddl-temporary-keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will change the defaultConf.IgnoreDDLTemporaryKeyword to true.

but, I cannot agree to your renaming advice. reserve-ddl-temporary-keyword is ambiguous compare with ignore-xxx for new user, TEMPORARY is standard SQL syntax, why need to reserve? set to false might be interpreted as

  1. no TEMPORARY syntax supported for tidb, or
  2. just ignore TEMPORARY

@sre-bot
Copy link
Contributor

sre-bot commented Mar 24, 2020

@ffutop, please update your pull request.

@bb7133
Copy link
Member

bb7133 commented Mar 30, 2020

Hi @ffutop , please update the PR, thank you!

@sre-bot
Copy link
Contributor

sre-bot commented Mar 31, 2020

@ffutop, please update your pull request.

…for-temporary-table

# Conflicts:
#	config/config.go
#	ddl/error.go
@sre-bot
Copy link
Contributor

sre-bot commented Apr 8, 2020

@ffutop, please update your pull request.

1 similar comment
@sre-bot
Copy link
Contributor

sre-bot commented Apr 15, 2020

@ffutop, please update your pull request.

@sre-bot
Copy link
Contributor

sre-bot commented May 1, 2020

@ffutop PR closed due to no update for a long time. Feel free to reopen it anytime.

@sre-bot sre-bot closed this May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/config contribution This PR is from a community contributor. sig/sql-infra SIG: SQL Infra status/LGT1 Indicates that a PR has LGTM 1. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix TiDB behavior: temporary table
8 participants