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

planner: fix missing array clone when building table filter for mv index access path (#52613) #52621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/planner/core/indexmerge_unfinished_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func buildIntoAccessPath(
// 2. Collect the final table filter
// We always put all filters in the top level AND list except for the OR list into the final table filters.
// Whether to put the OR list into the table filters also depends on the needSelectionGlobal.
tableFilter := allConds[:]
tableFilter := slices.Clone(allConds)
if !needSelectionGlobal {
tableFilter = slices.Delete(tableFilter, orListIdxInAllConds, orListIdxInAllConds+1)
}
Expand Down
22 changes: 22 additions & 0 deletions tests/integrationtest/r/planner/core/indexmerge_path.result
Original file line number Diff line number Diff line change
Expand Up @@ -963,3 +963,25 @@ Projection_8 6.66 root planner__core__indexmerge_path.t.col_37->Column#7
└─TableRowIDScan_11 10.00 cop[tikv] table:t keep order:false, stats:pseudo
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';
MIN(col_37)
drop table if exists t1;
CREATE TABLE `t1` (
`col_44` date NOT NULL,
`col_45` json DEFAULT NULL,
`col_46` blob NOT NULL,
PRIMARY KEY (`col_44`) /*T![clustered_index] CLUSTERED */,
UNIQUE KEY `idx_16` (`col_46`(3)),
KEY `idx_17` ((cast(`col_45` as double array)))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO t1 VALUES('1988-07-19','[0.9233398239291353, 0.9396459773262974, 0.540018481999012, 0.181978533893545]',x'652539286c5f7e6b482a7265575a');
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]');
col_44 col_45
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]');
id estRows task access object operator info
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)))
└─IndexMerge 26.59 root type: union
├─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
├─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
├─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
├─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
└─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))
└─TableRowIDScan 39.94 cop[tikv] table:t1 keep order:false, stats:pseudo
14 changes: 14 additions & 0 deletions tests/integrationtest/t/planner/core/indexmerge_path.test
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,17 @@ INSERT INTO `t` VALUES('[12474495489656359869, 14407883655486982855, 42211846364

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';
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';

# TestIssue52609
drop table if exists t1;
CREATE TABLE `t1` (
`col_44` date NOT NULL,
`col_45` json DEFAULT NULL,
`col_46` blob NOT NULL,
PRIMARY KEY (`col_44`) /*T![clustered_index] CLUSTERED */,
UNIQUE KEY `idx_16` (`col_46`(3)),
KEY `idx_17` ((cast(`col_45` as double array)))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO t1 VALUES('1988-07-19','[0.9233398239291353, 0.9396459773262974, 0.540018481999012, 0.181978533893545]',x'652539286c5f7e6b482a7265575a');
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]');
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]');