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

batchPoint leads to tidb panic when KeyPartition column is part of multi-column index #51313

Closed
jiyfhust opened this issue Feb 26, 2024 · 3 comments · Fixed by #51315
Closed
Labels
affects-7.5 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@jiyfhust
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table tkey (col1 int not null, col2 varchar(32) not null, col3 int not null, unique(col1, col2)) partition by key(col2) partitions 4;
insert into tkey values(1, 'a', 1), (2, 'b', 2);
select col1, col2, col3 from tkey where col1 = 1 and col2 = 'a' or col1 = 3 and col2 = 'c';

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

mysql> select col1, col2, col3 from tkey where col1 = 1 and col2 = 'a' or col1 = 3 and col2 = 'c';
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
|    1 | a    |    1 |
+------+------+------+
1 row in set, 1 warning (0.01 sec)

3. What did you see instead (Required)

mysql> select col1, col2, col3 from tkey where col1 = 1 and col2 = 'a' or col1 = 3 and col2 = 'c';
ERROR 1105 (HY000): runtime error: index out of range [1] with length 1

4. What is your TiDB version? (Required)

master

@tiancaiamao
Copy link
Contributor

Which version of the master branch?
I try to follow this reproduce but explain show the plan use IndexLookUp instead of BatchPointGet

mysql> explain format='brief' select col1, col2, col3 from tkey where col1 = 1 and col2 = 'a' or col1 = 3 and col2 = 'c';
+-----------------------------+---------+-----------+------------------------------------+--------------------------------------------------------------------+
| id                          | estRows | task      | access object                      | operator info                                                      |
+-----------------------------+---------+-----------+------------------------------------+--------------------------------------------------------------------+
| IndexLookUp                 | 2.00    | root      | partition:p3                       |                                                                    |
| ├─IndexRangeScan(Build)     | 2.00    | cop[tikv] | table:tkey, index:col1(col1, col2) | range:[1 "a",1 "a"], [3 "c",3 "c"], keep order:false, stats:pseudo |
| └─TableRowIDScan(Probe)     | 2.00    | cop[tikv] | table:tkey                         | keep order:false, stats:pseudo                                     |
+-----------------------------+---------+-----------+------------------------------------+--------------------------------------------------------------------+
3 rows in set (0.00 sec)

Test in this commit.

commit 5ac8a5b4636162f1edcee38906d450a59267aa6e (HEAD -> master, origin/master, origin/HEAD)
Author: Yuanjia Zhang <zhangyuanjia@pingcap.com>
Date:   Mon Mar 4 19:20:05 2024 +0800

    planner: add more test cases for plan cache with generated columns (#51483)
    
    ref pingcap/tidb#45798

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Mar 4, 2024

@tiancaiamao You need to set session variables if your version with pr #51405 merged:

set session tidb_skip_missing_partition_stats=0;
set session tidb_opt_fix_control = "";

@jiyfhust
Copy link
Contributor Author

jiyfhust commented Mar 4, 2024

@tiancaiamao 944118c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants