Skip to content

Commit 8d4b52a

Browse files
authored
planner: fixed index out of range, in explicit partition pruning (pingcap#62468)
close pingcap#62458
1 parent 095ab56 commit 8d4b52a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

pkg/planner/core/point_get_plan.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ func isInExplicitPartitions(pi *model.PartitionInfo, idx int, names []ast.CIStr)
676676
if len(names) == 0 {
677677
return true
678678
}
679+
// partIdx can be -1 more to check issue #62458
680+
if pi == nil || idx < 0 || idx >= len(pi.Definitions) {
681+
return false
682+
}
679683
s := pi.Definitions[idx].Name.L
680684
for _, name := range names {
681685
if s == name.L {

tests/integrationtest/r/executor/issues.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,9 @@ NULL
10371037
SELECT IS_IPV6(NULL + INTERVAL 1 DAY);
10381038
IS_IPV6(NULL + INTERVAL 1 DAY)
10391039
NULL
1040+
CREATE TABLE test_62458 (c1 INT, c2 VARCHAR(255)) PARTITION BY LIST (c1) (PARTITION p1 VALUES IN (1, 2, 3), PARTITION p2 VALUES IN (4, 5, 6));
1041+
CREATE UNIQUE INDEX i ON test_62458 (c1);
1042+
DELETE FROM test_62458 PARTITION (p1) WHERE c1 = 15;
10401043
CREATE TABLE test_62457 (c INT) PARTITION BY RANGE (c) (PARTITION p VALUES LESS THAN (10));
10411044
ALTER TABLE test_62457 ADD COLUMN c2 INT AS (JSON_EXTRACT(c, '$.number')) VIRTUAL;
10421045
Error 3146 (22032): Invalid data type for JSON data in argument 1 to function json_extract; a JSON string or JSON type is required.

tests/integrationtest/t/executor/issues.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ SELECT IS_IPV4(IF(1, NULL, '127.0.0.1'));
791791
SELECT IS_IPV4_COMPAT(NULL);
792792
SELECT IS_IPV6(NULL + INTERVAL 1 DAY);
793793

794+
# TestIssue62458 should no error
795+
CREATE TABLE test_62458 (c1 INT, c2 VARCHAR(255)) PARTITION BY LIST (c1) (PARTITION p1 VALUES IN (1, 2, 3), PARTITION p2 VALUES IN (4, 5, 6));
796+
CREATE UNIQUE INDEX i ON test_62458 (c1);
797+
DELETE FROM test_62458 PARTITION (p1) WHERE c1 = 15;
794798
# TestIssue62457 should raise error
795799
CREATE TABLE test_62457 (c INT) PARTITION BY RANGE (c) (PARTITION p VALUES LESS THAN (10));
796800
-- error 3146

0 commit comments

Comments
 (0)