Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pingcap/tidb into indexha…
Browse files Browse the repository at this point in the history
…shjoin_order
  • Loading branch information
XuHuaiyu committed Sep 25, 2019
2 parents e5198eb + 1342cba commit 2d566ef
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 101 deletions.
13 changes: 13 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,16 @@ HashLeftJoin_10 7984.01 root semi join, inner:TableReader_16, equal:[eq(Column#1
└─TableReader_16 9980.01 root data:Selection_15
└─Selection_15 9980.01 cop not(isnull(Column#4)), not(isnull(Column#5))
└─TableScan_14 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo
drop table t;
CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,
i int(10) unsigned DEFAULT NULL,
x int(10) unsigned DEFAULT 0,
PRIMARY KEY (`id`)
);
explain select row_number() over( partition by i ) - x as rnk from t;
id count task operator info
Projection_7 10000.00 root minus(Column#7, Column#3)
└─Window_8 10000.00 root row_number() over(partition by Column#2)
└─Sort_11 10000.00 root Column#2:asc
└─TableReader_10 10000.00 root data:TableScan_9
└─TableScan_9 10000.00 cop table:t, range:[0,+inf], keep order:false, stats:pseudo
9 changes: 9 additions & 0 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,12 @@ create table t1(a int, b int);
drop table if exists t2;
create table t2(a int, b int);
explain select * from t1 where t1.a in (select t2.a as a from t2 where t2.b > t1.b order by t1.b);

# test fields with windows function
drop table t;
CREATE TABLE t (id int(10) unsigned NOT NULL AUTO_INCREMENT,
i int(10) unsigned DEFAULT NULL,
x int(10) unsigned DEFAULT 0,
PRIMARY KEY (`id`)
);
explain select row_number() over( partition by i ) - x as rnk from t;
3 changes: 0 additions & 3 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,6 @@ func FormatSQL(sql string, pps variable.PreparedParams) stringutil.StringerFunc
func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) {
sessVars := a.Ctx.GetSessionVars()
level := log.GetLevel()
if level > zapcore.WarnLevel {
return
}
cfg := config.GetGlobalConfig()
costTime := time.Since(a.Ctx.GetSessionVars().StartTime)
threshold := time.Duration(atomic.LoadUint64(&cfg.Log.SlowThreshold)) * time.Millisecond
Expand Down
2 changes: 1 addition & 1 deletion executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (e *AnalyzeFastExec) getSampRegionsRowCount(bo *tikv.Backoffer, needRebuild
var resp *tikvrpc.Response
var rpcCtx *tikv.RPCContext
// we always use the first follower when follower read is enabled
rpcCtx, *err = e.cache.GetRPCContext(bo, loc.Region, e.ctx.GetSessionVars().GetReplicaRead(), 0)
rpcCtx, *err = e.cache.GetTiKVRPCContext(bo, loc.Region, e.ctx.GetSessionVars().GetReplicaRead(), 0)
if *err != nil {
return
}
Expand Down
66 changes: 66 additions & 0 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,72 @@ func (b *builtinPowSig) vectorized() bool {
return true
}

func (b *builtinCeilRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
if result.IsNull(i) {
continue
}
f64s[i] = math.Ceil(f64s[i])
}
return nil
}

func (b *builtinCeilRealSig) vectorized() bool {
return true
}

func (b *builtinRoundRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
if result.IsNull(i) {
continue
}
f64s[i] = types.Round(f64s[i], 0)
}
return nil
}

func (b *builtinRoundRealSig) vectorized() bool {
return true
}

func (b *builtinRoundWithFracRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
n := input.NumRows()
buf1, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalInt(b.ctx, input, buf1); err != nil {
return err
}

x := result.Float64s()
d := buf1.Int64s()
result.MergeNulls(buf1)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
x[i] = types.Round(x[i], int(d[i]))
}
return nil
}

func (b *builtinRoundWithFracRealSig) vectorized() bool {
return true
}

func (b *builtinTruncateRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions expression/builtin_math_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
},
ast.Round: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-100, 100}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-100, 100}}},
},
ast.Pow: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}, geners: []dataGenerator{&rangeRealGener{0, 10, 0.5}, &rangeRealGener{0, 100, 0.5}}},
},
ast.Ceil: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal}, geners: nil},
},
ast.Truncate: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}},
},
Expand Down
6 changes: 3 additions & 3 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ func (a *havingWindowAndOrderbyExprResolver) Leave(n ast.Node) (node ast.Node, o
a.inWindowSpec = false
case *ast.ColumnNameExpr:
resolveFieldsFirst := true
if a.inAggFunc || a.inWindowFunc || a.inWindowSpec || (a.orderBy && a.inExpr) {
if a.inAggFunc || a.inWindowFunc || a.inWindowSpec || (a.orderBy && a.inExpr) || a.curClause == fieldList {
resolveFieldsFirst = false
}
if !a.inAggFunc && !a.orderBy {
Expand Down Expand Up @@ -1315,7 +1315,7 @@ func (a *havingWindowAndOrderbyExprResolver) Leave(n ast.Node) (node ast.Node, o
var err error
index, err = a.resolveFromSchema(v, a.p.Schema())
_ = err
if index == -1 && a.curClause != windowClause {
if index == -1 && a.curClause != fieldList {
index, a.err = resolveFromSelectFields(v, a.selectFields, false)
if index != -1 && a.curClause == havingClause && ast.HasWindowFlag(a.selectFields[index].Expr) {
a.err = ErrWindowInvalidWindowFuncAliasUse.GenWithStackByArgs(v.Name.Name.O)
Expand Down Expand Up @@ -1420,7 +1420,7 @@ func (b *PlanBuilder) resolveWindowFunction(sel *ast.SelectStmt, p LogicalPlan)
colMapper: b.colMapper,
outerSchemas: b.outerSchemas,
}
extractor.curClause = windowClause
extractor.curClause = fieldList
for _, field := range sel.Fields.Fields {
if !ast.HasWindowFlag(field.Expr) {
continue
Expand Down
5 changes: 5 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,11 @@ func (s *testPlanSuite) TestWindowFunction(c *C) {
sql: "SELECT NTH_VALUE(fieldA, -1) OVER (w1 PARTITION BY fieldB ORDER BY fieldB , fieldA ) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as temp WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )",
result: "[planner:1210]Incorrect arguments to nth_value",
},
// Test issue 11943
{
sql: "SELECT ROW_NUMBER() OVER (partition by b) + a FROM t",
result: "TableReader(Table(t))->Sort->Window(row_number() over(partition by Column#2))->Projection",
},
}

s.Parser.EnableWindowFunc(true)
Expand Down
2 changes: 0 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ const (
onClause
orderByClause
whereClause
windowClause
groupByClause
showStatement
globalOrderByClause
Expand All @@ -177,7 +176,6 @@ var clauseMsg = map[clauseCode]string{
groupByClause: "group statement",
showStatement: "show statement",
globalOrderByClause: "global ORDER clause",
windowClause: "field list", // For window functions that in field list.
}

// PlanBuilder builds Plan from an ast.Node.
Expand Down
13 changes: 8 additions & 5 deletions store/tikv/client_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func (c *batchCommandsClient) send(request *tikvpb.BatchCommandsRequest, entries
c.batched.Store(requestID, entries[i])
}
if err := c.client.Send(request); err != nil {
logutil.BgLogger().Error(
"batch commands send error",
logutil.BgLogger().Info(
"sending batch commands meets error",
zap.String("target", c.target),
zap.Error(err),
)
Expand Down Expand Up @@ -260,7 +260,7 @@ func (c *batchCommandsClient) reCreateStreamingClientOnce(err error) error {

return nil
}
logutil.BgLogger().Error(
logutil.BgLogger().Info(
"batchRecvLoop re-create streaming fail",
zap.String("target", c.target),
zap.Error(err),
Expand All @@ -283,8 +283,11 @@ func (c *batchCommandsClient) batchRecvLoop(cfg config.TiKVClient, tikvTransport
for {
resp, err := c.recv()
if err != nil {
logutil.BgLogger().Error(
"batchRecvLoop error when receive",
if c.isStopped() {
return
}
logutil.BgLogger().Info(
"batchRecvLoop fails when receiving, needs to reconnect",
zap.String("target", c.target),
zap.Error(err),
)
Expand Down
3 changes: 2 additions & 1 deletion store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type copTask struct {
respChan chan *copResponse
storeAddr string
cmdType tikvrpc.CmdType
storeType StoreType
}

func (r *copTask) String() string {
Expand Down Expand Up @@ -655,7 +656,7 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch
ScanDetail: true,
})
startTime := time.Now()
resp, rpcCtx, err := sender.SendReqCtx(bo, req, task.region, ReadTimeoutMedium)
resp, rpcCtx, err := sender.SendReqCtx(bo, req, task.region, ReadTimeoutMedium, task.storeType)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down
Loading

0 comments on commit 2d566ef

Please sign in to comment.