Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Apr 29, 2024
1 parent e8a33ed commit 3537e1f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/executor/index_merge_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ func (w *partialIndexWorker) needPartitionHandle() (bool, error) {
col := cols[outputOffsets[len(outputOffsets)-1]]

needPartitionHandle := w.partitionTableMode && len(w.byItems) > 0
hasExtraCol := col.ID == model.ExtraPhysTblID
hasExtraCol := col.ID == model.ExtraPidColID || col.ID == model.ExtraPhysTblID

// There will be two needPartitionHandle != hasExtraCol situations.
// Only `needPartitionHandle` == true and `hasExtraCol` == false are not allowed.
Expand Down
39 changes: 33 additions & 6 deletions tests/integrationtest/r/globalindex/mem_index_merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE `tpk2` (
`d` int(11) NOT NULL AUTO_INCREMENT,
KEY `idx_bc` (`b`,`c`),
UNIQUE KEY `uidx_a` (`a`),
UNIQUE KEY `uidx_ac` (`a`, `c`),
KEY `idx_c` (`c`)
) PARTITION BY HASH (`c`) PARTITIONS 5;
insert into tpk2 values (1, 2, 1, 1), (3, 6, 3, 3);
Expand Down Expand Up @@ -49,10 +50,10 @@ a b c d
## for indexMerge union with specified PARTITION
explain select /*+ use_index_merge(tpk2, uidx_a, idx_bc) */ * from tpk2 partition(p1) where a=1 or b=4;
id estRows task access object operator info
Projection_5 11.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─UnionScan_6 11.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4))
Projection_5 11.00 root NULL globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─UnionScan_6 11.00 root NULL or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4))
└─IndexMerge_12 11.00 root partition:p1 type: union
├─Selection_9(Build) 1.00 cop[tikv] in(_tidb_pid, 108)
├─Selection_9(Build) 1.00 cop[tikv] NULL in(_tidb_pid, pid1)
│ └─IndexRangeScan_7 1.00 cop[tikv] table:tpk2, index:uidx_a(a) range:[1,1], keep order:false, stats:pseudo
├─IndexRangeScan_10(Build) 10.00 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:false, stats:pseudo
└─TableRowIDScan_11(Probe) 11.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo
Expand All @@ -62,10 +63,10 @@ a b c d
## for indexMerge intersection with specified PARTITION
explain select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) where a > 1 or c > 1;
id estRows task access object operator info
Projection_5 5555.56 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─UnionScan_6 5555.56 root or(gt(globalindex__mem_index_merge.tpk2.a, 1), gt(globalindex__mem_index_merge.tpk2.c, 1))
Projection_5 5555.56 root NULL globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─UnionScan_6 5555.56 root NULL or(gt(globalindex__mem_index_merge.tpk2.a, 1), gt(globalindex__mem_index_merge.tpk2.c, 1))
└─IndexMerge_12 5555.56 root partition:p1 type: union
├─Selection_9(Build) 3333.33 cop[tikv] in(_tidb_pid, 108)
├─Selection_9(Build) 3333.33 cop[tikv] NULL in(_tidb_pid, pid1)
│ └─IndexRangeScan_7 3333.33 cop[tikv] table:tpk2, index:uidx_a(a) range:(1,+inf], keep order:false, stats:pseudo
├─IndexRangeScan_10(Build) 3333.33 cop[tikv] table:tpk2, index:idx_c(c) range:(1,+inf], keep order:false, stats:pseudo
└─TableRowIDScan_11(Probe) 5555.56 cop[tikv] table:tpk2 keep order:false, stats:pseudo
Expand All @@ -84,6 +85,7 @@ CREATE TABLE `tpk2` (
`d` int(11) NOT NULL,
KEY `idx_bc` (`b`,`c`),
UNIQUE KEY `uidx_a` (`a`),
UNIQUE KEY `uidx_ac` (`a`, `c`),
KEY `idx_c` (`c`),
PRIMARY KEY(`d`, `c`)
) PARTITION BY HASH (`d`) PARTITIONS 5;
Expand Down Expand Up @@ -152,4 +154,29 @@ a b c d
select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) where a > 0 or c > 0;
a b c d
1 2 1 1
## for indexMerge union with order by limit
explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1;
id estRows task access object operator info
Projection_8 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─Limit_15 1.00 root offset:0, count:1
└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4))
└─IndexMerge_27 1.00 root partition:all type: union
├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, stats:pseudo
├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, stats:pseudo
└─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo
select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1;
a b c d
1 2 1 1
explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1;
id estRows task access object operator info
Projection_8 1.00 root globalindex__mem_index_merge.tpk2.a, globalindex__mem_index_merge.tpk2.b, globalindex__mem_index_merge.tpk2.c, globalindex__mem_index_merge.tpk2.d
└─Limit_15 1.00 root offset:0, count:1
└─UnionScan_22 1.00 root or(eq(globalindex__mem_index_merge.tpk2.a, 1), eq(globalindex__mem_index_merge.tpk2.b, 4))
└─IndexMerge_27 1.00 root partition:all type: union
├─IndexRangeScan_23(Build) 0.91 cop[tikv] table:tpk2, index:uidx_ac(a, c) range:[1,1], keep order:true, desc, stats:pseudo
├─IndexRangeScan_25(Build) 0.91 cop[tikv] table:tpk2, index:idx_bc(b, c) range:[4,4], keep order:true, desc, stats:pseudo
└─TableRowIDScan_26(Probe) 1.00 cop[tikv] table:tpk2 keep order:false, stats:pseudo
select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1;
a b c d
2 4 2 2
rollback;
11 changes: 11 additions & 0 deletions tests/integrationtest/t/globalindex/mem_index_merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE `tpk2` (
`d` int(11) NOT NULL AUTO_INCREMENT,
KEY `idx_bc` (`b`,`c`),
UNIQUE KEY `uidx_a` (`a`),
UNIQUE KEY `uidx_ac` (`a`, `c`),
KEY `idx_c` (`c`)
) PARTITION BY HASH (`c`) PARTITIONS 5;

Expand All @@ -30,11 +31,13 @@ select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 where a > 1 and c
select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 where a > 0 and c > 0;

--echo ## for indexMerge union with specified PARTITION
--replace_regex /in\(_tidb_pid, [0-9]+\)/in(_tidb_pid, pid1)/
explain select /*+ use_index_merge(tpk2, uidx_a, idx_bc) */ * from tpk2 partition(p1) where a=1 or b=4;
--sorted_result
select /*+ use_index_merge(tpk2, uidx_a, idx_bc) */ * from tpk2 partition(p1) where a=1 or b=4;

--echo ## for indexMerge intersection with specified PARTITION
--replace_regex /in\(_tidb_pid, [0-9]+\)/in(_tidb_pid, pid1)/
explain select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) where a > 1 or c > 1;
--sorted_result
select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) where a > 1 or c > 1;
Expand All @@ -52,6 +55,7 @@ CREATE TABLE `tpk2` (
`d` int(11) NOT NULL,
KEY `idx_bc` (`b`,`c`),
UNIQUE KEY `uidx_a` (`a`),
UNIQUE KEY `uidx_ac` (`a`, `c`),
KEY `idx_c` (`c`),
PRIMARY KEY(`d`, `c`)
) PARTITION BY HASH (`d`) PARTITIONS 5;
Expand Down Expand Up @@ -89,4 +93,11 @@ select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) whe
--sorted_result
select /*+ use_index_merge(tpk2, uidx_a, idx_c) */ * from tpk2 partition(p1) where a > 0 or c > 0;

--echo ## for indexMerge union with order by limit
explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1;
select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c limit 1;
explain select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1;
select /*+ use_index_merge(tpk2, uidx_ac, idx_bc) */ * from tpk2 where a = 1 or b = 4 order by c desc limit 1;

rollback;

0 comments on commit 3537e1f

Please sign in to comment.