-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: support create/drop expression index #14117
ddl: support create/drop expression index #14117
Conversation
/run-all-tests |
1 similar comment
/run-all-tests |
65301fc
to
5c5e4f9
Compare
03babd7
to
1abd378
Compare
4117477
to
0fbfd50
Compare
@Deardrops, @zimulala, @AilinKid, PTAL. |
@@ -1896,3 +1898,68 @@ func (s *testIntegrationSuite3) TestParserIssue284(c *C) { | |||
tk.MustExec("drop table test.t_parser_issue_284") | |||
tk.MustExec("drop table test.t_parser_issue_284_2") | |||
} | |||
|
|||
func (s *testIntegrationSuite6) TestAddExpressionIndex(c *C) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these tests to partition tables. And add a rollback test to test the add index operation, such as testAddIndexRollback
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
c.Assert(columns[3].Hidden, IsTrue) | ||
c.Assert(columns[4].Hidden, IsTrue) | ||
|
||
tk.MustQuery("select * from t;").Check(testkit.Rows("1 2.1")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test for index data like select b from t use index(idx_multi) where ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pr can't use expression index, should we add test using expression index explicitly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for index data will be added in following PR.
@@ -609,6 +609,19 @@ func (s *testSuite5) TestShowCreateTable(c *C) { | |||
" `a` varchar(123) DEFAULT NULL\n"+ | |||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", | |||
)) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to handle the SQL of show keys from t;
? It seems that we need to add a field of Expression
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I will support this in following PR.
@@ -77,6 +77,9 @@ func adjustColumnInfoInDropColumn(tblInfo *model.TableInfo, offset int) { | |||
oldCols[i].Offset = i - 1 | |||
} | |||
oldCols[offset].Offset = len(oldCols) - 1 | |||
// For expression index, we drop hidden columns and index simultaneously. | |||
// So we need to change the offset of expression index. | |||
offsetChanged[offset] = len(oldCols) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove this logic? It seems only the current expression index will use this hidden column. So we needn't update this column's offset when dropping this expression index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If remove this logic, the column offset of the expression index will be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it. At this time, the expression index only modifies the state, and it has not been actually deleted.
56178cf
to
4938b40
Compare
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
What problem does this PR solve?
support create/drop expression index
What is changed and how it works?
create expression index
, we build hidden columns and put it into tableInfo, since it always in the end of column, we don't need to adjust its offsets in wrieOrg.drop expression index
, we need to remove hidden columns.Drop Primary Index
andDrop Index
. We can roll back them in state WriteOnly theoretically, and it will be handled in the future.Check List
Tests
Code changes
Side effects
Related changes
Release note