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

why there are so many kinds of "table lock" related syntax? #31767

Closed
tiancaiamao opened this issue Jan 18, 2022 · 9 comments
Closed

why there are so many kinds of "table lock" related syntax? #31767

tiancaiamao opened this issue Jan 18, 2022 · 9 comments
Labels
component/parser type/question The issue belongs to a question. type/stale This issue has not been updated for a long time.

Comments

@tiancaiamao
Copy link
Contributor

General Question

I want to lock the table to try the @@tidb_enable_point_get_cache, but misuse the syntax.
I used alter table t read only ... it doesn't work as expected.

Then I take a glance at the parser.y file, and found we have soooooooooooooo many related syntax:

alter table t lock none
alter table t lock = none
alter table t lock = default
alter table t lock = shared
alter table t lock = exclusive

alter table t read only
alter table t read write

lock table t read
lock table t read local
lock table t write
lock table t write local

unlock table
admin cleanup table lock XX

alter table t cache
alter table t nocache

Each of the above statement is legal, no grammar check error.
But what does they mean? why sooooooooooooooooo many different syntax?
As a developer, I'm quite confused (not to say the real user).

@tiancaiamao tiancaiamao added type/question The issue belongs to a question. component/parser labels Jan 18, 2022
@tiancaiamao
Copy link
Contributor Author

@crazycs520 any idea?

@tiancaiamao
Copy link
Contributor Author

alter table t cache
alter table t nocache

Is what I added for #25293, it's non-standard MySQL syntax and the feature is not a part of MySQL.

@tiancaiamao
Copy link
Contributor Author

lock table t read
lock table t read local
lock table t write
lock table t write local

lock table seems to be also TiDB extension, it's used to make a table read only in one server (local keyword),
or in the whole cluster scope.
It seems this is not GA feature? I can't find the official document for it https://docs.pingcap.com/tidb/stable

@zimulala
Copy link
Contributor

I think some of the following are MySQL syntax:

alter table t lock none
alter table t lock = none
alter table t lock = default
alter table t lock = shared
alter table t lock = exclusive

Related link: https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#:~:text=LOCK%20%5B%3D%5D%20%7BDEFAULT%20%7C%20NONE%20%7C%20SHARED%20%7C%20EXCLUSIVE%7D

@CbcWestwolf
Copy link
Member

It seems this is not GA feature? I can't find the official document for it https://docs.pingcap.com/tidb/stable

It is an experimental feature in TiDB but a formal feature in MySQL.

tidb> lock table t read;
Query OK, 0 rows affected, 1 warning (0.00 sec)

tidb> show warnings;
+---------+------+-----------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                               |
+---------+------+-----------------------------------------------------------------------------------------------------------------------+
| Warning | 1235 | LOCK TABLES is not supported. To enable this experimental feature, set 'enable-table-lock' in the configuration file. |
+---------+------+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

@crazycs520
Copy link
Contributor

the following syntax are also MySQL syntax:

lock table t read
lock table t read local
lock table t write
lock table t write local

https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html

But TiDB add 2 special lock type: read local, write local, which use for tispark.

@tiancaiamao tiancaiamao changed the title why there are so many "table lock" related syntax? why there are so many kinds of "table lock" related syntax? Jan 18, 2022
@tiancaiamao
Copy link
Contributor Author

OK... ALTER TABLE t LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE} is standard MySQL syntax.
It's a dummy operation in TiDB.

and UNLOCK TABLE UNLOCK TABLES are also MySQL syntax.
UNLOCK TABLES clean the table locks of the current session...
UNLOCK TABLE ... I don't know what's it for.

alter table t read only
alter table t read write

They are seems to be bug, MySQL don't have such syntax and it's introduced in pingcap/parser#1095,
it should be replaced by the lock table t read only syntax.

@mjonss
Copy link
Contributor

mjonss commented Jan 18, 2022

LOCK TABLE t {read|write}/UNLOCK TABLE[S] is really old MySQL syntax developed for MyISAM tables, which lacked transactions. It locked the full table for that session/connection until a new transaction/ddl or UNLOCK TABLES. It is not supported by TiDB. The local keyword is probably TiDB enhancements as mentioned above.
UNLOCK TABLE has the same meaning as UNLOCK TABLES in MySQL.

ALTER TABLE t ... LOCK = ... was added in MySQL while starting to support ONLINE SCHEMA CHANGES. Later ALGORITHM was also added, so one could limit DDL to INSTANT changes, aka Meta data only changes, just like TiDBs ddl without reorg.
The ALTER TALBE t ... LOCK = ... where SHARED means block changes but allow SELECT and EXCLUSIVE means block all other sessions access to the table during the DDL. This could be used as a way to avoid duplicate key or NULL value issues from other sessions during DDL.

@jebter
Copy link

jebter commented Sep 3, 2024

The issue has not been updated for too long, so I will close it,if there are any updates, you can reopen it

@jebter jebter closed this as completed Sep 3, 2024
@jebter jebter added the type/stale This issue has not been updated for a long time. label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/parser type/question The issue belongs to a question. type/stale This issue has not been updated for a long time.
Projects
None yet
Development

No branches or pull requests

6 participants