-
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 drop index for the partitioned table. #7306
Conversation
ddl/db_test.go
Outdated
(9, 'study desk', '2006-09-16'), | ||
(10, 'lava lamp', '1998-12-25');`) | ||
|
||
tk.MustExec("create index idx1 on tr (purchased)") |
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.
It test drop index, so how about create the table with index together?
ddl/db_test.go
Outdated
tk.MustQuery("select count(purchased) from tr use index(idx1)").Check(testkit.Rows("10")) | ||
tk.MustExec("admin check table tr") | ||
// Wait for add index done. | ||
time.Sleep(waitForCleanDataInterval) |
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.
There is no need to wait.
create index idx1 on tr (purchased)
blocks for a while, as long as it returns, add index will be done.
@@ -436,7 +436,7 @@ func onDropIndex(t *meta.Meta, job *model.Job) (ver int64, _ error) { | |||
job.Args[0] = indexInfo.ID | |||
} else { | |||
job.FinishTableJob(model.JobStateDone, model.StateNone, ver, tblInfo) | |||
job.Args = append(job.Args, indexInfo.ID) | |||
job.Args = append(job.Args, indexInfo.ID, getPartitionIDs(tblInfo)) |
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 the table is not a partition, what will getPartitionIDs
return?
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.
getPartitionIDs
will return []int64{}
.
f8f0298
to
95355b8
Compare
table/tables/tables.go
Outdated
@@ -81,10 +81,10 @@ func MockTableFromMeta(tblInfo *model.TableInfo) table.Table { | |||
|
|||
var t Table | |||
initTableCommon(&t.tableCommon, tblInfo, tblInfo.ID, columns, nil) | |||
if err := initTableIndices(&t.tableCommon); err != nil { |
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.
Is this change relevant to the PR?
ddl/db_test.go
Outdated
c.Assert(err, IsNil, Commentf("err:%v", errors.ErrorStack(err))) | ||
case <-ticker.C: | ||
step := 10 | ||
for i := num; i < num+step; i++ { |
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 random data will always locate in the first partition...
95355b8
to
56b719e
Compare
@tiancaiamao @winkyao PTAL. |
LGTM |
ddl/delete_range.go
Outdated
} | ||
} | ||
return nil | ||
} |
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 len(partitionIDs) > 0 {
} else {
}
This could make code more clear.
@@ -279,9 +279,20 @@ func insertJobIntoDeleteRangeTable(ctx sessionctx.Context, job *model.Job) error | |||
tableID := job.TableID | |||
var indexName interface{} | |||
var indexID int64 | |||
if err := job.DecodeArgs(&indexName, &indexID); err != nil { | |||
var partitionIDs []int64 | |||
if err := job.DecodeArgs(&indexName, &indexID, &partitionIDs); err != nil { |
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.
We have the job.TableID
. Could we get the partition IDs from the info schema instead of job arguments?
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.
When modifying table schema, there is a new table info and an old one.
It's easy to get the stale IDs if we get it from the info schema. @shenli
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.
@shenli Existing function getPartitionIDs
.
func getPartitionIDs(table *model.TableInfo) []int64 {
if table.GetPartitionInfo() == nil {
return []int64{}
}
partitionIDs := make([]int64, 0, len(table.Partition.Definitions))
for _, def := range table.Partition.Definitions {
partitionIDs = append(partitionIDs, def.ID)
}
return partitionIDs
}
Is it clearer.
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.
In drop index
, because the ddl
of same table is serial executed, so get partition IDs from info schema is ok.
But I remain neutral, get the partition IDs from the info schema or use job arguments are both ok for me. >v<
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.
"It's easy to get the stale IDs if we get it from the info schema." Can not understand this. We should guarantee that we will get the correct schema when doing DDL.
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.
You can ignore the comment @shenli , I just give a hint on how to achieve this...
We should guarantee that we will get the correct schema when doing DDL.
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.
@ciscoxll Please address the comment. We do not need to put partition IDs in the job argument.
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 agree with shenli. please address the comment.
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.
ddl/db_test.go
Outdated
for i := num; i < num+step; i++ { | ||
rnd := rand.Intn(num) | ||
s.mustExec(c, "update partition_drop_idx set c2 = 1 where c1 = ?", rnd) | ||
s.mustExec(c, "insert into partition_drop_idx values (?, ?, ?)", i, i, i) |
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
may more than 20, then, insert into partition_drop_idx values (20,20,20)"
should return error: (1604, 'locate partition failed')
You can use |
@shenli @winkyao @crazycs520 PTAL. |
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 |
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
What have you changed? (mandatory)
support drop index for the partitioned table
Take this as an example:
What is the type of the changes? (mandatory)
New feature
How has this PR been tested? (mandatory)
Unit tests.
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No
Does this PR affect tidb-ansible update? (mandatory)
No
Does this PR need to be added to the release notes? (mandatory)
No