Skip to content

Commit

Permalink
plan: refine the handle check to use point get plan for prepare state…
Browse files Browse the repository at this point in the history
…ment (pingcap#7732)
  • Loading branch information
zz-jason authored Sep 25, 2018
1 parent e79bd94 commit 869e201
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,11 @@ HashLeftJoin_10 156250000.00 root left outer join, inner:HashLeftJoin_16, left c
│ └─TableScan_17 10000.00 cop table:t3, range:[-inf,+inf], keep order:false, stats:pseudo
└─TableReader_20 10000.00 root data:TableScan_19
└─TableScan_19 10000.00 cop table:t4, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
create table t(a bigint primary key, b bigint);
desc select * from t where a = 1;
id count task operator info
Point_Get_1 1.00 root table:t, handle:1
desc select * from t where a = '1';
id count task operator info
Point_Get_1 1.00 root table:t, handle:1
11 changes: 8 additions & 3 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SELECT 1, @a, @@autocommit as a, c1 from t;
SET @b = "123";
SELECT @b + "123";
# TODO: the field name for 1 + 1 should be "1 + 1", but now is 2
# we may discuss whether to support it like in MySQL later.
# we may discuss whether to support it like in MySQL later.
SELECT 1 + 1;

SELECT 1 a, 1 as a, 1 + 1 a;
Expand Down Expand Up @@ -60,7 +60,7 @@ SELECT * from (SELECT 1, 1) as a;
--error ER_DUP_FIELDNAME
SELECT * from (SELECT * FROM t, t2) as a;

# Select bool field
# Select bool field
DROP TABLE IF EXISTS t;
CREATE TABLE t (c1 INT, c2 INT);
INSERT INTO t VALUES (1, 2), (1, 1), (1, 3);
Expand All @@ -86,7 +86,7 @@ select c2 from t where not null is null;
# unary field name
select !(1 + 2);

# - +
# - +
select + - 1, --1, +-+-+1, + "123";
select --------------------1, ++++++++++++++++++++1;
select --+(1 + 1), +-+-(1 * 1);
Expand Down Expand Up @@ -158,3 +158,8 @@ select count(a) from t where b>0 group by a, b order by a limit 1;
drop table if exists t;
create table t (id int primary key, a int, b int);
explain select * from (t t1 left join t t2 on t1.a = t2.a) left join (t t3 left join t t4 on t3.a = t4.a) on t2.b = 1;

drop table if exists t;
create table t(a bigint primary key, b bigint);
desc select * from t where a = 1;
desc select * from t where a = '1';
10 changes: 7 additions & 3 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt) *PointGetP
return nil
}
handleDatum := findPKHandle(tbl, pairs)
if handleDatum.Kind() == types.KindInt64 {
if handleDatum.Kind() != types.KindNull {
if len(pairs) != 1 {
return nil
}
Expand All @@ -193,15 +193,19 @@ func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt) *PointGetP
return nil
}
p := newPointGetPlan(ctx, schema, tbl)
p.Handle = handleDatum.GetInt64()
var err error
p.Handle, err = handleDatum.ToInt64(ctx.GetSessionVars().StmtCtx)
if err != nil {
return nil
}
return p
}
for _, idxInfo := range tbl.Indices {
if !idxInfo.Unique {
continue
}
if idxInfo.State != model.StatePublic {
return nil
continue
}
idxValues := getIndexValues(idxInfo, pairs)
if idxValues == nil {
Expand Down

0 comments on commit 869e201

Please sign in to comment.