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
executor: fix update global index return duplicate key error #42311
executor: fix update global index return duplicate key error #42311
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Hi @L-maple. Thanks for your PR. I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
20def73
to
41af99a
Compare
41af99a
to
59384c6
Compare
To pass the |
59384c6
to
9dc4187
Compare
resolved |
71a6f7e
to
28d808d
Compare
28d808d
to
ed7b12b
Compare
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 for this PR, Not sure should we concerned about rollback for this situation. /cc @tiancaiamao
tidb/table/tables/partition.go
Lines 1604 to 1609 in fc166ff
// UpdateRecord should be side effect free, but there're two steps here. | |
// What would happen if step1 succeed but step2 meets error? It's hard | |
// to rollback. | |
// So this special order is chosen: add record first, errors such as | |
// 'Key Already Exists' will generally happen during step1, errors are | |
// unlikely to happen in step2. |
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
@@ -1952,6 +1953,106 @@ func TestDropPartitionWithGlobalIndex(t *testing.T) { | |||
require.Equal(t, 2, cnt) | |||
} | |||
|
|||
func TestGlobalIndexInsertInDropPartition(t *testing.T) { |
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 test suppose to hit the change/bug or just there for completeness?
tk.MustQuery("select * from test_global use index(idx_b) order by a").Check(testkit.Rows("1 1 1", "2 11 11", "8 8 8", "13 12 12")) | ||
} | ||
|
||
func TestGlobalIndexUpdateInDropPartition(t *testing.T) { |
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.
Same here, is this test suppose to hit the change/bug or just there for completeness?
just for complement. there is a ut for drop partition with global index,but no ut exist for write when ddl happens.
---- Replied Message ----
| From | Mattias ***@***.***> |
| Date | 03/22/2023 23:22 |
| To | ***@***.***> |
| Cc | Changjie ***@***.***>***@***.***> |
| Subject | Re: [pingcap/tidb] executor: fix update global index return duplicate key error (PR #42311) |
@mjonss approved this pull request.
LGTM
In ddl/db_partition_test.go:
@@ -1952,6 +1953,106 @@ func TestDropPartitionWithGlobalIndex(t *testing.T) {
require.Equal(t, 2, cnt)
}
+func TestGlobalIndexInsertInDropPartition(t *testing.T) {
Is this test suppose to hit the change/bug or just there for completeness?
In ddl/db_partition_test.go:
+ tk.MustExec("drop table if exists test_global")
+ tk.MustExec(`create table test_global ( a int, b int, c int)
+ partition by range( a ) (
+ partition p1 values less than (10),
+ partition p2 values less than (20),
+ partition p3 values less than (30)
+ );`)
+ tk.MustExec("alter table test_global add unique index idx_b (b);")
+ tk.MustExec("insert into test_global values (1, 1, 1), (8, 8, 8), (11, 11, 11), (12, 12, 12);")
+ tk.MustExec("update test_global set a = 2 where a = 11")
+ tk.MustExec("update test_global set a = 13 where a = 12")
+ tk.MustExec("analyze table test_global")
+ tk.MustQuery("select * from test_global use index(idx_b) order by a").Check(testkit.Rows("1 1 1", "2 11 11", "8 8 8", "13 12 12"))
+}
+
+func TestGlobalIndexUpdateInDropPartition(t *testing.T) {
Same here, is this test suppose to hit the change/bug or just there for completeness?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
if c.idxInfo.Global { | ||
if val, err := txn.GetMemBuffer().Get(context.Background(), key); err == nil { | ||
segs := tablecodec.SplitIndexValue(val) | ||
if len(segs.PartitionID) != 0 { | ||
_, pid, err := codec.DecodeInt(segs.PartitionID) | ||
if err != nil { | ||
return err | ||
} | ||
if pid != c.phyTblID { | ||
continue | ||
} | ||
} | ||
} | ||
} |
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 was a bit curious and I wonder if we should change the way we add the indexes here?
I mean if it is a global index, why add it with the physical table ids of the partitions?
/merge |
This pull request has been accepted and is ready to merge. Commit hash: ed7b12b
|
/retest |
/test all |
/retest |
What problem does this PR solve?
Issue Number: close #42312
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.