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: support create/drop expression index #14117

Merged
merged 32 commits into from
Jan 7, 2020

Conversation

wjhuang2016
Copy link
Member

@wjhuang2016 wjhuang2016 commented Dec 18, 2019

What problem does this PR solve?

support create/drop expression index

What is changed and how it works?

  1. For 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.
  2. For drop expression index, we need to remove hidden columns.
  3. Becase we need to remove hidden columns in drop expression index, we can't roll back in state WriteOnly. This will affect Drop Primary Index and Drop Index. We can roll back them in state WriteOnly theoretically, and it will be handled in the future.

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported function/method change

Side effects

Related changes

Release note

  • Support create/drop expression index

@wjhuang2016 wjhuang2016 requested a review from a team as a code owner December 18, 2019 09:34
@ghost ghost requested review from eurekaka and lzmhhh123 and removed request for a team December 18, 2019 09:34
@eurekaka eurekaka removed their request for review December 18, 2019 09:35
@lzmhhh123 lzmhhh123 removed their request for review December 18, 2019 09:39
@wjhuang2016
Copy link
Member Author

/run-all-tests

1 similar comment
@wjhuang2016
Copy link
Member Author

/run-all-tests

ddl/db_test.go Show resolved Hide resolved
ddl/ddl_api.go Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
util/admin/admin.go Outdated Show resolved Hide resolved
ddl/db_integration_test.go Show resolved Hide resolved
ddl/db_integration_test.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
@sre-bot
Copy link
Contributor

sre-bot commented Jan 5, 2020

@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) {
Copy link
Contributor

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.

Copy link
Member Author

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"))
Copy link
Contributor

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 ...?

Copy link
Member Author

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?

Copy link
Member Author

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.

ddl/index.go Outdated Show resolved Hide resolved
@@ -609,6 +609,19 @@ func (s *testSuite5) TestShowCreateTable(c *C) {
" `a` varchar(123) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))

Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 6, 2020
ddl/index.go Outdated Show resolved Hide resolved
ddl/rollingback.go Outdated Show resolved Hide resolved
executor/show_test.go Show resolved Hide resolved
util/admin/admin.go Outdated Show resolved Hide resolved
util/admin/admin.go Outdated Show resolved Hide resolved
@AilinKid
Copy link
Contributor

AilinKid commented Jan 6, 2020

LGTM

@AilinKid AilinKid added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 6, 2020
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jan 7, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 7, 2020

/run-all-tests

@sre-bot sre-bot merged commit f036eec into pingcap:master Jan 7, 2020
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
@wjhuang2016 wjhuang2016 deleted the expression_index_crate_index branch November 17, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants