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, executor: support point get as a option of DataSource #14775

Merged
merged 37 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f4a7122
planner, executor: support point get as a option of `DataSource`
lzmhhh123 Feb 12, 2020
49bf84a
fix panic
lzmhhh123 Feb 13, 2020
7a1f123
debug
lzmhhh123 Feb 14, 2020
7193950
fix
lzmhhh123 Feb 17, 2020
b948e4f
Merge branch 'master' into dev/point_get_as_ds
lzmhhh123 Feb 17, 2020
795b8ab
add test
lzmhhh123 Feb 17, 2020
ad6166f
Merge branch 'dev/point_get_as_ds' of https://github.com/lzmhhh123/ti…
lzmhhh123 Feb 17, 2020
8cafed0
add test data
lzmhhh123 Feb 17, 2020
d735f97
fix explain test
lzmhhh123 Feb 17, 2020
9477124
Merge branch 'master' into dev/point_get_as_ds
lzmhhh123 Feb 18, 2020
c0e2a8c
fix test
lzmhhh123 Feb 18, 2020
97a3aa8
fix fmt
lzmhhh123 Feb 18, 2020
f90b527
fix explain test
lzmhhh123 Feb 18, 2020
3e52e69
fix
lzmhhh123 Feb 18, 2020
57f28f1
Merge branch 'master' into dev/point_get_as_ds
lzmhhh123 Feb 18, 2020
5649d52
fix
lzmhhh123 Feb 19, 2020
0a42e9b
fix test
lzmhhh123 Feb 19, 2020
0f6bdce
Merge branch 'master' into dev/point_get_as_ds
lzmhhh123 Feb 19, 2020
30be7a7
Merge branch 'master' into dev/point_get_as_ds
lzmhhh123 Feb 20, 2020
34e37e8
fix test
lzmhhh123 Feb 20, 2020
9eef4b8
Merge remote-tracking branch 'origin/master' into dev/point_get_as_ds
lzmhhh123 Feb 26, 2020
9b3101f
Merge remote-tracking branch 'origin/master' into dev/point_get_as_ds
lzmhhh123 Mar 4, 2020
51ac6e5
fix test
lzmhhh123 Mar 4, 2020
cb7431b
Merge remote-tracking branch 'origin/master' into dev/point_get_as_ds
lzmhhh123 Mar 5, 2020
db5759c
address comments
lzmhhh123 Mar 5, 2020
9d10cbf
address comment
lzmhhh123 Mar 6, 2020
31d367b
address comment
lzmhhh123 Mar 6, 2020
379b185
Merge remote-tracking branch 'origin/master' into dev/point_get_as_ds
lzmhhh123 Mar 6, 2020
435a269
fix test
lzmhhh123 Mar 6, 2020
601f2d8
address comments
lzmhhh123 Mar 6, 2020
54a156a
fix explain test
lzmhhh123 Mar 6, 2020
ac2807d
a better condition format
lzmhhh123 Mar 6, 2020
2439afd
remove some unnecessary fields
lzmhhh123 Mar 6, 2020
263f226
Merge branch 'master' into dev/point_get_as_ds
eurekaka Mar 6, 2020
a5dfcae
if there is generate col, ban the point-get
lzmhhh123 Mar 9, 2020
44a2373
Merge branch 'dev/point_get_as_ds' of https://github.com/lzmhhh123/ti…
lzmhhh123 Mar 9, 2020
fb651da
Merge branch 'master' into dev/point_get_as_ds
sre-bot Mar 9, 2020
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
5 changes: 2 additions & 3 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ IndexLookUp_11 11.08 root
└─TableRowIDScan_9 33.33 cop[tikv] table:t1, keep order:false, stats:pseudo
explain select * from t1 where c1 = 1 and c2 > 1;
id estRows task operator info
TableReader_7 0.33 root data:Selection_6
└─Selection_6 0.33 cop[tikv] gt(test.t1.c2, 1)
└─TableRangeScan_5 1.00 cop[tikv] table:t1, range:[1,1], keep order:false, stats:pseudo
Selection_6 0.33 root gt(test.t1.c2, 1)
└─Point_Get_5 1.00 root table:t1, handle:1
explain select sum(t1.c1 in (select c1 from t2)) from t1;
id estRows task operator info
StreamAgg_12 1.00 root funcs:sum(Column#10)->Column#8
Expand Down
17 changes: 6 additions & 11 deletions cmd/explaintest/r/explain_easy_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ IndexLookUp_11 0.00 root
└─TableRowIDScan_9 0.00 cop[tikv] table:t1, keep order:false
explain select * from t1 where c1 = 1 and c2 > 1;
id estRows task operator info
TableReader_7 0.50 root data:Selection_6
└─Selection_6 0.50 cop[tikv] gt(test.t1.c2, 1)
└─TableRangeScan_5 1.00 cop[tikv] table:t1, range:[1,1], keep order:false
Selection_6 0.50 root gt(test.t1.c2, 1)
└─Point_Get_5 1.00 root table:t1, handle:1
explain select c1 from t1 where c1 in (select c2 from t2);
id estRows task operator info
HashLeftJoin_19 1985.00 root inner join, inner:HashAgg_23, equal:[eq(test.t1.c1, test.t2.c2)]
Expand Down Expand Up @@ -162,16 +161,12 @@ id estRows task operator info
TableDual_5 0.00 root rows:0
explain select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1, 1;
id estRows task operator info
IndexLookUp_14 1.00 root limit embedded(offset:1, count:1)
├─Limit_13(Build) 1.00 cop[tikv] offset:0, count:2
│ └─IndexRangeScan_11 1.00 cop[tikv] table:index_prune, index:a, b, range:[1010010404050976781 26467085526790,1010010404050976781 26467085526790], keep order:false
└─TableRowIDScan_12(Probe) 1.00 cop[tikv] table:index_prune, keep order:false, stats:pseudo
Limit_9 1.00 root offset:1, count:1
└─Point_Get_11 1.00 root table:index_prune, index:a b
explain select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1, 0;
id estRows task operator info
IndexLookUp_14 0.00 root limit embedded(offset:1, count:0)
├─Limit_13(Build) 1.00 cop[tikv] offset:0, count:1
│ └─IndexRangeScan_11 1.00 cop[tikv] table:index_prune, index:a, b, range:[1010010404050976781 26467085526790,1010010404050976781 26467085526790], keep order:false
└─TableRowIDScan_12(Probe) 0.00 cop[tikv] table:index_prune, keep order:false, stats:pseudo
Limit_9 0.00 root offset:1, count:0
└─Point_Get_11 1.00 root table:index_prune, index:a b
explain select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 0, 1;
id estRows task operator info
Point_Get_1 1.00 root table:index_prune, index:a b
Expand Down
39 changes: 13 additions & 26 deletions cmd/explaintest/r/partition_pruning.result
Original file line number Diff line number Diff line change
Expand Up @@ -334,50 +334,43 @@ a
1
EXPLAIN SELECT * FROM t1 WHERE a = 1;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p1, range:[1,1], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:1, partition:p1
SELECT * FROM t1 WHERE a = 2 order by a;
a
2
EXPLAIN SELECT * FROM t1 WHERE a = 2;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p2, range:[2,2], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:2, partition:p2
SELECT * FROM t1 WHERE a = 3 order by a;
a
3
EXPLAIN SELECT * FROM t1 WHERE a = 3;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p3, range:[3,3], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:3, partition:p3
SELECT * FROM t1 WHERE a = 4 order by a;
a
4
EXPLAIN SELECT * FROM t1 WHERE a = 4;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p4, range:[4,4], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:4, partition:p4
SELECT * FROM t1 WHERE a = 5 order by a;
a
5
EXPLAIN SELECT * FROM t1 WHERE a = 5;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p5, range:[5,5], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:5, partition:p5
SELECT * FROM t1 WHERE a = 6 order by a;
a
6
EXPLAIN SELECT * FROM t1 WHERE a = 6;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:max, range:[6,6], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:6, partition:max
SELECT * FROM t1 WHERE a = 7 order by a;
a
7
EXPLAIN SELECT * FROM t1 WHERE a = 7;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:max, range:[7,7], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:7, partition:max
SELECT * FROM t1 WHERE a >= 1 order by a;
a
1
Expand Down Expand Up @@ -812,43 +805,37 @@ a
1
EXPLAIN SELECT * FROM t1 WHERE a = 1;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p1, range:[1,1], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:1, partition:p1
SELECT * FROM t1 WHERE a = 2;
a
2
EXPLAIN SELECT * FROM t1 WHERE a = 2;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p2, range:[2,2], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:2, partition:p2
SELECT * FROM t1 WHERE a = 3;
a
3
EXPLAIN SELECT * FROM t1 WHERE a = 3;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p3, range:[3,3], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:3, partition:p3
SELECT * FROM t1 WHERE a = 4;
a
4
EXPLAIN SELECT * FROM t1 WHERE a = 4;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p4, range:[4,4], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:4, partition:p4
SELECT * FROM t1 WHERE a = 5;
a
5
EXPLAIN SELECT * FROM t1 WHERE a = 5;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:max, range:[5,5], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:5, partition:max
SELECT * FROM t1 WHERE a = 6;
a
6
EXPLAIN SELECT * FROM t1 WHERE a = 6;
id estRows task operator info
TableReader_7 1.00 root data:TableRangeScan_6
└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:max, range:[6,6], keep order:false, stats:pseudo
Point_Get_6 1.00 root table:t1, handle:6, partition:max
SELECT * FROM t1 WHERE a >= 1 order by a;
a
1
Expand Down
18 changes: 18 additions & 0 deletions executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package executor

import (
"context"
"sort"

"github.com/pingcap/failpoint"
"github.com/pingcap/parser/model"
Expand Down Expand Up @@ -44,6 +45,8 @@ type BatchPointGetExec struct {
values [][]byte
index int
rowDecoder *rowcodec.ChunkDecoder
keepOrder bool
desc bool
}

// Open implements the Executor interface.
Expand Down Expand Up @@ -118,6 +121,14 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
dedup[s] = struct{}{}
keys = append(keys, idxKey)
}
if e.keepOrder {
sort.Slice(keys, func(i int, j int) bool {
if e.desc {
return keys[i].Cmp(keys[j]) > 0
}
return keys[i].Cmp(keys[j]) < 0
})
}

// Fetch all handles.
handleVals, err = batchGetter.BatchGet(ctx, keys)
Expand Down Expand Up @@ -151,6 +162,13 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
// Wait `UPDATE` finished
failpoint.InjectContext(ctx, "batchPointGetRepeatableReadTest-step2", nil)
})
} else if e.keepOrder {
sort.Slice(e.handles, func(i int, j int) bool {
if e.desc {
return e.handles[i] > e.handles[j]
}
return e.handles[i] < e.handles[j]
})
}

keys := make([]kv.Key, len(e.handles))
Expand Down
3 changes: 3 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ func (b *executorBuilder) buildIndexLookUpReader(v *plannercore.PhysicalIndexLoo

ret.ranges = is.Ranges
executorCounterIndexLookUpExecutor.Inc()

sctx := b.ctx.GetSessionVars().StmtCtx
sctx.IndexNames = append(sctx.IndexNames, is.Table.Name.O+":"+is.Index.Name.O)
sctx.TableIDs = append(sctx.TableIDs, ts.Table.ID)
Expand Down Expand Up @@ -2908,6 +2909,8 @@ func (b *executorBuilder) buildBatchPointGet(plan *plannercore.BatchPointGetPlan
idxInfo: plan.IndexInfo,
rowDecoder: decoder,
startTS: startTS,
keepOrder: plan.KeepOrder,
desc: plan.Desc,
lock: plan.Lock,
waitTime: plan.LockWaitTime,
}
Expand Down
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ func (s *testSuiteP2) TestIsPointGet(c *C) {
ctx := tk.Se.(sessionctx.Context)
tests := map[string]bool{
"select * from help_topic where name='aaa'": false,
"select 1 from help_topic where name='aaa'": true,
"select 1 from help_topic where name='aaa'": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this test mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means whether there is a point-get plan for the query.

"select * from help_topic where help_topic_id=1": true,
"select * from help_topic where help_category_id=1": false,
}
Expand Down
39 changes: 13 additions & 26 deletions expression/testdata/partition_pruner_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
{
"SQL": "explain select * from t1 where id = 7 and a = 6",
"Result": [
"TableReader_8 0.00 root data:Selection_7",
"└─Selection_7 0.00 cop[tikv] eq(test_partition.t1.a, 6)",
" └─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p7, range:[7,7], keep order:false, stats:pseudo"
"Selection_7 0.00 root eq(test_partition.t1.a, 6)",
"└─Point_Get_6 1.00 root table:t1, handle:7, partition:p7"
]
},
{
Expand All @@ -19,16 +18,13 @@
{
"SQL": "explain select * from t2 where id = 9 and a = -110",
"Result": [
"IndexLookUp_8 1.00 root ",
"├─IndexRangeScan_6(Build) 1.00 cop[tikv] table:t2, partition:p1, index:id, a, range:[9 -110,9 -110], keep order:false, stats:pseudo",
"└─TableRowIDScan_7(Probe) 1.00 cop[tikv] table:t2, partition:p1, keep order:false, stats:pseudo"
"Point_Get_6 1.00 root table:t2, index:id a, partition:p1"
]
},
{
"SQL": "explain select * from t1 where id = -17",
"Result": [
"TableReader_7 1.00 root data:TableRangeScan_6",
"└─TableRangeScan_6 1.00 cop[tikv] table:t1, partition:p7, range:[-17,-17], keep order:false, stats:pseudo"
"Point_Get_6 1.00 root table:t1, handle:-17, partition:p7"
]
},
{
Expand All @@ -42,34 +38,25 @@
{
"SQL": "explain select * from t1 join t2 on (t1.id = t2.id) where t1.id = 5 and t2.a = 7",
"Result": [
"HashLeftJoin_10 1.00 root CARTESIAN inner join, inner:IndexLookUp_16",
"├─IndexLookUp_16(Build) 1.00 root ",
"│ ├─IndexRangeScan_14(Build) 1.00 cop[tikv] table:t2, partition:p2, index:id, a, range:[5 7,5 7], keep order:false, stats:pseudo",
"│ └─TableRowIDScan_15(Probe) 1.00 cop[tikv] table:t2, partition:p2, keep order:false, stats:pseudo",
"└─TableReader_13(Probe) 1.00 root data:TableRangeScan_12",
" └─TableRangeScan_12 1.00 cop[tikv] table:t1, partition:p5, range:[5,5], keep order:false, stats:pseudo"
"HashLeftJoin_10 1.00 root CARTESIAN inner join, inner:Point_Get_13",
"├─Point_Get_13(Build) 1.00 root table:t2, index:id a, partition:p2",
"└─Point_Get_12(Probe) 1.00 root table:t1, handle:5, partition:p5"
]
},
{
"SQL": "explain select * from t1 left join t2 on t1.id = 1 and t2.a = 2 where t2.id = 7",
"Result": [
"HashLeftJoin_9 1.00 root CARTESIAN inner join, inner:IndexLookUp_15",
"├─IndexLookUp_15(Build) 1.00 root ",
"│ ├─IndexRangeScan_13(Build) 1.00 cop[tikv] table:t2, partition:p9, index:id, a, range:[7 2,7 2], keep order:false, stats:pseudo",
"│ └─TableRowIDScan_14(Probe) 1.00 cop[tikv] table:t2, partition:p9, keep order:false, stats:pseudo",
"└─TableReader_12(Probe) 1.00 root data:TableRangeScan_11",
" └─TableRangeScan_11 1.00 cop[tikv] table:t1, partition:p1, range:[1,1], keep order:false, stats:pseudo"
"HashLeftJoin_9 1.00 root CARTESIAN inner join, inner:Point_Get_12",
"├─Point_Get_12(Build) 1.00 root table:t2, index:id a, partition:p9",
"└─Point_Get_11(Probe) 1.00 root table:t1, handle:1, partition:p1"
]
},
{
"SQL": "explain select * from t2 join t1 on t1.id = t2.id and t2.a = t1.id and t2.id = 12",
"Result": [
"HashLeftJoin_9 1.00 root CARTESIAN inner join, inner:TableReader_15",
"├─TableReader_15(Build) 1.00 root data:TableRangeScan_14",
"│ └─TableRangeScan_14 1.00 cop[tikv] table:t1, partition:p2, range:[12,12], keep order:false, stats:pseudo",
"└─IndexLookUp_13(Probe) 1.00 root ",
" ├─IndexRangeScan_11(Build) 1.00 cop[tikv] table:t2, partition:p4, index:id, a, range:[12 12,12 12], keep order:false, stats:pseudo",
" └─TableRowIDScan_12(Probe) 1.00 cop[tikv] table:t2, partition:p4, keep order:false, stats:pseudo"
"HashLeftJoin_9 1.00 root CARTESIAN inner join, inner:Point_Get_12",
"├─Point_Get_12(Build) 1.00 root table:t1, handle:12, partition:p2",
"└─Point_Get_11(Probe) 1.00 root table:t2, index:id a, partition:p4"
]
},
{
Expand Down
Loading