Skip to content

Commit 9599845

Browse files
time-and-fate3AceShowHand
authored andcommitted
planner: fix missing array clone when building table filter for mv index access path (pingcap#52613)
close pingcap#52609
1 parent 822a8d2 commit 9599845

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

pkg/planner/core/indexmerge_unfinished_path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func buildIntoAccessPath(
411411
// 2. Collect the final table filter
412412
// We always put all filters in the top level AND list except for the OR list into the final table filters.
413413
// Whether to put the OR list into the table filters also depends on the needSelectionGlobal.
414-
tableFilter := allConds[:]
414+
tableFilter := slices.Clone(allConds)
415415
if !needSelectionGlobal {
416416
tableFilter = slices.Delete(tableFilter, orListIdxInAllConds, orListIdxInAllConds+1)
417417
}

tests/integrationtest/r/planner/core/indexmerge_path.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,25 @@ Projection_8 6.66 root planner__core__indexmerge_path.t.col_37->Column#7
963963
└─TableRowIDScan_11 10.00 cop[tikv] table:t keep order:false, stats:pseudo
964964
SELECT /*+ use_index_merge(t)*/ MIN(col_37) FROM t WHERE col_38 BETWEEN '1984-12-13' AND '1975-01-28' OR JSON_CONTAINS(col_37, '138480458355390957') GROUP BY col_38 HAVING col_38 != '1988-03-22';
965965
MIN(col_37)
966+
drop table if exists t1;
967+
CREATE TABLE `t1` (
968+
`col_44` date NOT NULL,
969+
`col_45` json DEFAULT NULL,
970+
`col_46` blob NOT NULL,
971+
PRIMARY KEY (`col_44`) /*T![clustered_index] CLUSTERED */,
972+
UNIQUE KEY `idx_16` (`col_46`(3)),
973+
KEY `idx_17` ((cast(`col_45` as double array)))
974+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
975+
INSERT INTO t1 VALUES('1988-07-19','[0.9233398239291353, 0.9396459773262974, 0.540018481999012, 0.181978533893545]',x'652539286c5f7e6b482a7265575a');
976+
SELECT col_44, col_45 FROM t1 WHERE NOT (col_44 BETWEEN '1980-03-18' AND '2011-10-24') GROUP BY col_46,col_45 HAVING JSON_CONTAINS(col_45, '0.540018481999012') OR JSON_OVERLAPS(col_45, '[0.5785147169732324,0.8314968898215304,0.5226516826882698]');
977+
col_44 col_45
978+
EXPLAIN format=brief SELECT /*+ use_index_merge(t1) */ col_44, col_45 FROM t1 WHERE NOT (col_44 BETWEEN '1980-03-18' AND '2011-10-24') GROUP BY col_46,col_45 HAVING JSON_CONTAINS(col_45, '0.540018481999012') OR JSON_OVERLAPS(col_45, '[0.5785147169732324,0.8314968898215304,0.5226516826882698]');
979+
id estRows task access object operator info
980+
Selection 31.95 root or(json_contains(planner__core__indexmerge_path.t1.col_45, cast(cast("0.540018481999012", json BINARY), json BINARY)), json_overlaps(planner__core__indexmerge_path.t1.col_45, cast(cast("[0.5785147169732324,0.8314968898215304,0.5226516826882698]", json BINARY), json BINARY)))
981+
└─IndexMerge 26.59 root type: union
982+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:idx_17(cast(`col_45` as double array)) range:[0.540018481999012,0.540018481999012], keep order:false, stats:pseudo
983+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:idx_17(cast(`col_45` as double array)) range:[0.5785147169732324,0.5785147169732324], keep order:false, stats:pseudo
984+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:idx_17(cast(`col_45` as double array)) range:[0.8314968898215304,0.8314968898215304], keep order:false, stats:pseudo
985+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t1, index:idx_17(cast(`col_45` as double array)) range:[0.5226516826882698,0.5226516826882698], keep order:false, stats:pseudo
986+
└─Selection(Probe) 26.59 cop[tikv] or(lt(planner__core__indexmerge_path.t1.col_44, 1980-03-18 00:00:00.000000), gt(planner__core__indexmerge_path.t1.col_44, 2011-10-24 00:00:00.000000))
987+
└─TableRowIDScan 39.94 cop[tikv] table:t1 keep order:false, stats:pseudo

tests/integrationtest/t/planner/core/indexmerge_path.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,17 @@ INSERT INTO `t` VALUES('[12474495489656359869, 14407883655486982855, 42211846364
393393

394394
EXPLAIN SELECT /*+ use_index_merge(t)*/ MIN(col_37) FROM t WHERE col_38 BETWEEN '1984-12-13' AND '1975-01-28' OR JSON_CONTAINS(col_37, '138480458355390957') GROUP BY col_38 HAVING col_38 != '1988-03-22';
395395
SELECT /*+ use_index_merge(t)*/ MIN(col_37) FROM t WHERE col_38 BETWEEN '1984-12-13' AND '1975-01-28' OR JSON_CONTAINS(col_37, '138480458355390957') GROUP BY col_38 HAVING col_38 != '1988-03-22';
396+
397+
# TestIssue52609
398+
drop table if exists t1;
399+
CREATE TABLE `t1` (
400+
`col_44` date NOT NULL,
401+
`col_45` json DEFAULT NULL,
402+
`col_46` blob NOT NULL,
403+
PRIMARY KEY (`col_44`) /*T![clustered_index] CLUSTERED */,
404+
UNIQUE KEY `idx_16` (`col_46`(3)),
405+
KEY `idx_17` ((cast(`col_45` as double array)))
406+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
407+
INSERT INTO t1 VALUES('1988-07-19','[0.9233398239291353, 0.9396459773262974, 0.540018481999012, 0.181978533893545]',x'652539286c5f7e6b482a7265575a');
408+
SELECT col_44, col_45 FROM t1 WHERE NOT (col_44 BETWEEN '1980-03-18' AND '2011-10-24') GROUP BY col_46,col_45 HAVING JSON_CONTAINS(col_45, '0.540018481999012') OR JSON_OVERLAPS(col_45, '[0.5785147169732324,0.8314968898215304,0.5226516826882698]');
409+
EXPLAIN format=brief SELECT /*+ use_index_merge(t1) */ col_44, col_45 FROM t1 WHERE NOT (col_44 BETWEEN '1980-03-18' AND '2011-10-24') GROUP BY col_46,col_45 HAVING JSON_CONTAINS(col_45, '0.540018481999012') OR JSON_OVERLAPS(col_45, '[0.5785147169732324,0.8314968898215304,0.5226516826882698]');

0 commit comments

Comments
 (0)