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

Pessimistic lock doesn't work on a partition table when index merge is used #31024

Closed
guo-shaoge opened this issue Dec 26, 2021 · 3 comments
Closed
Assignees
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Dec 26, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t1, t2;
create table t1 (c_datetime datetime, c1 int, c2 int, primary key (c_datetime), key(c1), key(c2)) partition by range (to_days(c_datetime)) ( partition p0 values less than (to_days('2020-02-01')), partition p1 values less than (to_days('2020-04-01')), partition p2 values less than           (to_days('2020-06-01')), partition p3 values less than maxvalue) ;
create table t2 (c_datetime datetime, unique key(c_datetime));
insert into t1 values ('2020-06-26 03:24:00', 1, 1), ('2020-02-21 07:15:33', 2, 2), ('2020-04-27 13:50:58', 3, 3);
insert into t2 values ('2020-01-10 09:36:00'), ('2020-02-04 06:00:00'), ('2020-06-12 03:45:18');
SET GLOBAL tidb_txn_mode = 'pessimistic';

txn1:

begin;
select /*+ use_index_merge(t1) */ * from t1 join t2 on t1.c_datetime >= t2.c_datetime where t1.c1 < 10 or t1.c2 < 10 for update; 

txn2:

begin;
update t1 set c_datetime = '2020-06-26 03:24:00' where c1 = 1;

2. What did you expect to see? (Required)

txn2 will be blocked.

3. What did you see instead (Required)

txn2 didn't be blocked.

mysql> begin;
Query OK, 0 rows affected (0.01 sec)
mysql> update t1 set c_datetime = '2020-06-26 03:24:00' where c1 = 1;
Query OK, 0 rows affected (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 0

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()
                                |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.4.0-alpha-498-g404895c04a-dirty
Edition: Community
Git Commit Hash: 404895c04a5183d6bf759cc910e642475f4f9f2b
Git Branch: master
UTC Build Time: 2021-12-25 06:18:03
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@guo-shaoge guo-shaoge added the type/bug The issue is confirmed as a bug. label Dec 26, 2021
@guo-shaoge guo-shaoge self-assigned this Dec 26, 2021
@guo-shaoge
Copy link
Collaborator Author

Related to #14921 and #21148.

We need to add extraPIDColumnIndex when build final TableReader for IndexMerge, just like #21148 did.

@mjonss
Copy link
Contributor

mjonss commented Feb 14, 2022

/component tablepartition

@ti-chi-bot ti-chi-bot added the component/tablepartition This issue is related to Table Partition of TiDB. label Feb 14, 2022
mjonss added a commit to mjonss/tidb that referenced this issue Feb 14, 2022
@mjonss
Copy link
Contributor

mjonss commented Mar 3, 2022

Fixed by #31634.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. component/tablepartition This issue is related to Table Partition of TiDB. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
5 participants