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

planner: include "CREATE/DROP TEMPORARY TABLE" to noop functions (##609) #22860

Merged
merged 4 commits into from
Feb 28, 2021

Conversation

nayuta-yanagisawa
Copy link
Contributor

@nayuta-yanagisawa nayuta-yanagisawa commented Feb 21, 2021

What problem does this PR solve?

Issue Number: close pingcap/parser#609

Problem Summary:

Currently, TiDB ignores the TEMPORARY keyword in "CREATE/DROP TEMPORARY TABLE" statements.

What is changed and how it works?

I added "CREATE/DROP TEMPORARY TABLE" statements to noop functions. The statements returns errors when and only when tidb_enable_noop_functions = OFF.

mysql> select @@tidb_enable_noop_functions;
+------------------------------+
| @@tidb_enable_noop_functions |
+------------------------------+
|                            0 |
+------------------------------+
1 row in set (0.00 sec)

mysql> CREATE TEMPORARY TABLE t (a INT);
ERROR 1235 (42000): function CREATE TEMPORARY TABLE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
mysql> DROP TEMPORARY TABLE t;
ERROR 1235 (42000): function DROP TEMPORARY TABLE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions
mysql> set tidb_enable_noop_functions=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@tidb_enable_noop_functions;
+------------------------------+
| @@tidb_enable_noop_functions |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

mysql> CREATE TEMPORARY TABLE t (a INT);
Query OK, 0 rows affected, 1 warning (0.07 sec)

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

mysql> show warnings;
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                                                                                      |
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1064 | 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 22 near "TABLE t (a INT)"TiDB doesn't support TEMPORARY TABLE, TEMPORARY will be parsed but ignored.  |
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Note that "CREATE/DROP TEMPORARY SEQUENCE" statements are out of the scope of the pull request. TiDB seems not to support the statements as far as I read the documentation, TiDB SEQUENCE GENERATOR. In fact, TiDB v4.0 returns syntax errors for the statements.

mysql> \s
--------------
mysql  Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Connection id:          4
Current database:
Current user:           [email protected]
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.7.25-TiDB-v4.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Protocol version:       10
Connection:             127.0.0.1 via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
TCP port:               4000
Binary data as:         Hexadecimal
--------------

mysql> CREATE TEMPORARY SEQUENCE seq START WITH 100;
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 25 near "SEQUENCE seq START WITH 100"

mysql> DROP TEMPORARY SEQUENCE seq;
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 23 near "SEQUENCE seq"

Related changes

Check List

Tests

  • Unit test

Side effects

  • Breaking backward compatibility

Release note

  • Let "CREATE/DROP TEMPORARY TABLE" return errors if tidb_enable_noop_functions = OFF.

@nayuta-yanagisawa nayuta-yanagisawa requested a review from a team as a code owner February 21, 2021 17:57
@nayuta-yanagisawa nayuta-yanagisawa requested review from lzmhhh123 and removed request for a team February 21, 2021 17:57
@ti-srebot ti-srebot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Feb 21, 2021
@sre-bot
Copy link
Contributor

sre-bot commented Feb 21, 2021

@nayuta-yanagisawa nayuta-yanagisawa force-pushed the issue-609 branch 2 times, most recently from ee38a99 to 81daea9 Compare February 21, 2021 18:40
…ngcap#609)

TiDB ignores the TEMPORARY keyword in "CREATE/DROP TEMPORARY TABLE" statements.
Report errors when and only when tidb_enable_noop_functions = OFF.
@nayuta-yanagisawa
Copy link
Contributor Author

Force pushed to fix the commit message.

@morgo
Copy link
Contributor

morgo commented Feb 21, 2021

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 21, 2021
@bb7133 bb7133 added the compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. label Feb 22, 2021
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Feb 22, 2021
ti-srebot
ti-srebot previously approved these changes Feb 22, 2021
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Feb 22, 2021
@bb7133 bb7133 added the require-LGT3 Indicates that the PR requires three LGTM. label Feb 22, 2021
@bb7133
Copy link
Member

bb7133 commented Feb 22, 2021

PTAL @zz-jason

@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 24, 2021
@morgo
Copy link
Contributor

morgo commented Feb 24, 2021

For reviewers: note that TEMPORARY TABLES have very different semantics to regular tables. It is very unlikely that by parsing but ignoring the TEMPORARY keyword an app will function fine.

A longer explaination:

  • Temporary tables can use the same name as regular tables. When querying, the temporary table namespace takes precedence.
  • Temporary tables are per-session, and automatically cleaned up when the session ends. If a regular table is used, there will typically be an error trying to create the table because it already exists.
  • (Relates to point above) Temporary tables are often used for the same use-case as CTEs (build a list of rows and then perform a followup operation on them). Because temporary tables are usually session scope, there are no concurrency risks. But in TiDB there will be, as all sessions can read/write to the temporary table.

This is a really useful improvement to prevent incorrect usage and likely data corruption.

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Member

@zz-jason: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • zz-jason

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot
Copy link
Member

@nayuta-yanagisawa: GitHub didn't allow me to assign the following users: committer.

Note that only pingcap members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @committer

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@morgo morgo removed the require-LGT3 Indicates that the PR requires three LGTM. label Feb 27, 2021
@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

/LGTM

@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

/merge

@ti-chi-bot
Copy link
Member

@morgo: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

@morgo: /merge in this pull request requires 2 /lgtm.

In response to this:

/merge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@morgo morgo added the sig/sql-infra SIG: SQL Infra label Feb 27, 2021
@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

/lgtm

@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

I removed the require-LGT3 tag because it looked like the bot was misbehaving. But now I think the previous lgtm's may have failed because of the missing sig.

@hi-rustin do you mind taking a look?

@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

/run-all-tests

@morgo
Copy link
Contributor

morgo commented Feb 27, 2021

/run-e2e-test

@Rustin170506
Copy link
Member

I removed the require-LGT3 tag because it looked like the bot was misbehaving.

What is the misbehaving you are talking about? I think everything was fine before the require-LGT3 was removed. Now the bot can't merge because the number of lgtms doesn't match the required lgtms (it may look like a bug, but it's actually because require-LGT3 was removed). You should now add back require-LGT3 and it will work fine.

@Rustin170506
Copy link
Member

I removed the require-LGT3 tag because it looked like the bot was misbehaving.

What is the misbehaving you are talking about? I think everything was fine before the require-LGT3 was removed. Now the bot can't merge because the number of lgtms doesn't match the required lgtms (it may look like a bug, but it's actually because require-LGT3 was removed). You should now add back require-LGT3 and it will work fine.

I modified the code so that it also merges when the number of lgtm is greater than the requested number. (But this is rarely the case, except in the above case), because the bot will only respond and reply to the requested number, instead of growing lgtm number infinitely.

@Rustin170506
Copy link
Member

/run-e2e-test

Also this test was broken last week, the robot will not require this test to pass.

@Rustin170506
Copy link
Member

Rustin170506 commented Feb 28, 2021

/assign @committer

Here committer does not mean someone called committer. you can /assign @morgo to request morgo to merge your PR. You can find all the committers at this link: https://prow.tidb.io/tichi/repos/pingcap/tidb/pulls/22860/owners

/assign @morgo

@morgo morgo added the require-LGT3 Indicates that the PR requires three LGTM. label Feb 28, 2021
@morgo morgo merged commit 4b90ef4 into pingcap:master Feb 28, 2021
@nayuta-yanagisawa nayuta-yanagisawa deleted the issue-609 branch February 28, 2021 07:38
nayuta-yanagisawa added a commit to nayuta-yanagisawa/docs that referenced this pull request Feb 28, 2021
nayuta-yanagisawa added a commit to nayuta-yanagisawa/docs that referenced this pull request Feb 28, 2021
nayuta-yanagisawa added a commit to nayuta-yanagisawa/docs that referenced this pull request Feb 28, 2021
TomShawn added a commit to pingcap/docs that referenced this pull request Mar 4, 2021
* Update doc according to pingcap/tidb#22860

pingcap/parser#609
pingcap/tidb#22860

* Update sql-statements/sql-statement-create-table.md

Co-authored-by: TomShawn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. require-LGT3 Indicates that the PR requires three LGTM. sig/sql-infra SIG: SQL Infra size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix TiDB behavior: temporary table
8 participants