-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-21181 Add Support for Generated Invisible Primary Keys #4718
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
Open
jaeheonshim
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
jaeheonshim:MDEV-21181
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+408
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| CREATE TABLE t0 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t0; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| SET sql_generate_invisible_primary_key=ON; | ||
| CREATE TABLE t1 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| INSERT INTO t1 VALUES (3, 0); | ||
| INSERT INTO t1 VALUES (4, 0); | ||
| SELECT _rowid, t1.* FROM t1; | ||
| _rowid c1 c2 | ||
| 1 3 0 | ||
| 2 4 0 | ||
| ALTER TABLE t1 ADD c3 INT; | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| ALTER TABLE t1 ADD _inv_PK INT; | ||
| ALTER TABLE t1 ADD _inv_PK1 INT; | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
| ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists | ||
| ALTER TABLE t1 ADD PRIMARY KEY (c1); | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t1 0 PRIMARY 1 c1 A 2 NULL NULL BTREE NO | ||
| SELECT _rowid, t1.* FROM t1; | ||
| _rowid c1 c2 c3 _inv_PK _inv_PK1 | ||
| 3 3 0 NULL NULL NULL | ||
| 4 4 0 NULL NULL NULL | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
| CREATE TABLE t2 (c1 INT, c2 INT, _inv_PK INT); | ||
| SHOW INDEX FROM t2; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| CREATE TABLE t3 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t3; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| CREATE TABLE t4 (_inv_PK SERIAL INVISIBLE PRIMARY KEY, c2 INT); | ||
| ALTER TABLE t4 ADD PRIMARY KEY (c2); | ||
| ERROR 42000: Multiple primary key defined | ||
| SHOW INDEX FROM t4; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t4 0 PRIMARY 1 _inv_PK A 0 NULL NULL BTREE NO | ||
| DROP TABLE t0, t1, t2, t3, t4; | ||
| SET sql_generate_invisible_primary_key=OFF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # | ||
| # Test of sql_generate_invisible_primary_key option without debug (MDEV-21181) | ||
| # | ||
|
|
||
| # | ||
| # When option is off, invisible PK is not generated | ||
| # | ||
| CREATE TABLE t0 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t0; | ||
|
|
||
| SET sql_generate_invisible_primary_key=ON; | ||
|
|
||
| # | ||
| # Check that PK index gets created when not specified in CREATE TABLE | ||
| # | ||
| CREATE TABLE t1 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| INSERT INTO t1 VALUES (3, 0); | ||
| INSERT INTO t1 VALUES (4, 0); | ||
| SELECT _rowid, t1.* FROM t1; | ||
|
|
||
| # | ||
| # Check that generated PK persists on ALTER TABLE without new PK | ||
| # | ||
| ALTER TABLE t1 ADD c3 INT; | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| # | ||
| # Check that adding column with name of generated PK succeeds | ||
| # | ||
| ALTER TABLE t1 ADD _inv_PK INT; | ||
| ALTER TABLE t1 ADD _inv_PK1 INT; | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| # | ||
| # Trying to drop autogenerated PK should fail | ||
| # | ||
| --error ER_CANT_DROP_FIELD_OR_KEY | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
|
|
||
| # | ||
| # Check that generated PK is dropped on ALTER TABLE with new PK | ||
| # | ||
| ALTER TABLE t1 ADD PRIMARY KEY (c1); | ||
| SHOW INDEX FROM t1; | ||
| SELECT _rowid, t1.* FROM t1; | ||
|
|
||
| # | ||
| # Check that user PK that replaced generated PK can be dropped | ||
| # | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
|
|
||
| # | ||
| # Check that creating table with column named _inv_PK succeeds | ||
| # | ||
| CREATE TABLE t2 (c1 INT, c2 INT, _inv_PK INT); | ||
| SHOW INDEX FROM t2; | ||
|
|
||
| # | ||
| # Generated PK should be fully invisible to user | ||
| # | ||
| CREATE TABLE t3 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t3; | ||
|
|
||
| # | ||
| # Manually defined invisible primary key is not automatically dropped | ||
| # | ||
| CREATE TABLE t4 (_inv_PK SERIAL INVISIBLE PRIMARY KEY, c2 INT); | ||
| --error ER_MULTIPLE_PRI_KEY | ||
| ALTER TABLE t4 ADD PRIMARY KEY (c2); | ||
| SHOW INDEX FROM t4; | ||
|
|
||
| DROP TABLE t0, t1, t2, t3, t4; | ||
| SET sql_generate_invisible_primary_key=OFF; | ||
57 changes: 57 additions & 0 deletions
57
mysql-test/main/generate_invisible_primary_key_debug.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| SET SESSION debug_dbug="+d,test_invisible_index,test_completely_invisible"; | ||
| CREATE TABLE t0 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t0; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t0 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| SET sql_generate_invisible_primary_key=ON; | ||
| CREATE TABLE t1 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t1 0 PRIMARY 1 _inv_PK A 0 NULL NULL BTREE NO | ||
| t1 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| INSERT INTO t1 VALUES (3, 0); | ||
| INSERT INTO t1 VALUES (4, 0); | ||
| SELECT _rowid, t1.* FROM t1; | ||
| _rowid c1 c2 | ||
| 1 3 0 | ||
| 2 4 0 | ||
| ALTER TABLE t1 ADD c3 INT; | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t1 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| t1 0 PRIMARY 1 _inv_PK A 2 NULL NULL BTREE NO | ||
| ALTER TABLE t1 ADD _inv_PK INT; | ||
| ALTER TABLE t1 ADD _inv_PK1 INT; | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t1 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| t1 0 PRIMARY 1 _inv_PK2 A 2 NULL NULL BTREE NO | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
| ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists | ||
| ALTER TABLE t1 ADD PRIMARY KEY (c1); | ||
| SHOW INDEX FROM t1; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t1 0 PRIMARY 1 c1 A 2 NULL NULL BTREE NO | ||
| t1 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| SELECT _rowid, t1.* FROM t1; | ||
| _rowid c1 c2 c3 _inv_PK _inv_PK1 | ||
| 3 3 0 NULL NULL NULL | ||
| 4 4 0 NULL NULL NULL | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
| CREATE TABLE t2 (c1 INT, c2 INT, _inv_PK INT); | ||
| SHOW INDEX FROM t2; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t2 0 PRIMARY 1 _inv_PK1 A 0 NULL NULL BTREE NO | ||
| t2 1 invisible 1 invisible A NULL NULL NULL YES BTREE NO | ||
| SET SESSION debug_dbug=""; | ||
| CREATE TABLE t3 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t3; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| CREATE TABLE t4 (_inv_PK SERIAL INVISIBLE PRIMARY KEY, c2 INT); | ||
| ALTER TABLE t4 ADD PRIMARY KEY (c2); | ||
| ERROR 42000: Multiple primary key defined | ||
| SHOW INDEX FROM t4; | ||
| Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored | ||
| t4 0 PRIMARY 1 _inv_PK A 0 NULL NULL BTREE NO | ||
| DROP TABLE t0, t1, t2, t3, t4; | ||
| SET sql_generate_invisible_primary_key=OFF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # | ||
| # Test of sql_generate_invisible_primary_key option (MDEV-21181) | ||
| # | ||
| --source include/have_debug.inc | ||
|
|
||
| SET SESSION debug_dbug="+d,test_invisible_index,test_completely_invisible"; | ||
|
|
||
| # | ||
| # When option is off, invisible PK is not generated | ||
| # | ||
| CREATE TABLE t0 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t0; | ||
|
|
||
| SET sql_generate_invisible_primary_key=ON; | ||
|
|
||
| # | ||
| # Check that PK index gets created when not specified in CREATE TABLE | ||
| # | ||
| CREATE TABLE t1 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| INSERT INTO t1 VALUES (3, 0); | ||
| INSERT INTO t1 VALUES (4, 0); | ||
| SELECT _rowid, t1.* FROM t1; | ||
|
|
||
| # | ||
| # Check that generated PK persists on ALTER TABLE without new PK | ||
| # | ||
| ALTER TABLE t1 ADD c3 INT; | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| # | ||
| # Check that adding column with name of generated PK succeeds | ||
| # | ||
| ALTER TABLE t1 ADD _inv_PK INT; | ||
| ALTER TABLE t1 ADD _inv_PK1 INT; | ||
| SHOW INDEX FROM t1; | ||
|
|
||
| # | ||
| # Trying to drop autogenerated PK should fail | ||
| # | ||
| --error ER_CANT_DROP_FIELD_OR_KEY | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
|
|
||
| # | ||
| # Check that generated PK is dropped on ALTER TABLE with new PK | ||
| # | ||
| ALTER TABLE t1 ADD PRIMARY KEY (c1); | ||
| SHOW INDEX FROM t1; | ||
| SELECT _rowid, t1.* FROM t1; | ||
|
|
||
| # | ||
| # Check that user PK that replaced generated PK can be dropped | ||
| # | ||
| ALTER TABLE t1 DROP PRIMARY KEY; | ||
|
|
||
| # | ||
| # Check that creating table with column named _inv_PK succeeds | ||
| # | ||
| CREATE TABLE t2 (c1 INT, c2 INT, _inv_PK INT); | ||
| SHOW INDEX FROM t2; | ||
|
|
||
| SET SESSION debug_dbug=""; | ||
|
|
||
| # | ||
| # Generated PK should be fully invisible to user | ||
| # | ||
| CREATE TABLE t3 (c1 INT, c2 INT); | ||
| SHOW INDEX FROM t3; | ||
|
|
||
| # | ||
| # Manually defined invisible primary key is not automatically dropped | ||
| # | ||
| CREATE TABLE t4 (_inv_PK SERIAL INVISIBLE PRIMARY KEY, c2 INT); | ||
| --error ER_MULTIPLE_PRI_KEY | ||
| ALTER TABLE t4 ADD PRIMARY KEY (c2); | ||
| SHOW INDEX FROM t4; | ||
|
|
||
| DROP TABLE t0, t1, t2, t3, t4; | ||
| SET sql_generate_invisible_primary_key=OFF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.