Skip to content

Commit

Permalink
executor: add XAPI executor.
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Mar 25, 2016
1 parent a17cc4e commit 0157bcd
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 10 deletions.
54 changes: 54 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ import (
"math"

"github.com/juju/errors"
"github.com/ngaut/log"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/column"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/optimizer/plan"
"github.com/pingcap/tidb/parser/opcode"
"github.com/pingcap/tidb/sessionctx/autocommit"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/types"
"github.com/pingcap/tidb/xapi"
)

// executorBuilder builds an Executor from a Plan.
Expand Down Expand Up @@ -117,7 +120,33 @@ func (b *executorBuilder) buildFilter(src Executor, conditions []ast.ExprNode) E
}

func (b *executorBuilder) buildTableScan(v *plan.TableScan) Executor {
txn, err := b.ctx.GetTxn(false)
if err != nil {
b.err = err
return nil
}
table, _ := b.is.TableByID(v.Table.ID)
client := txn.GetClient()
var memDB bool
switch v.Fields()[0].DBName.L {
case "information_schema", "performance_schema":
memDB = true
}
if !memDB && client.SupportRequestType(kv.ReqTypeSelect, 0) && txn.IsReadOnly() {
log.Debug("xapi select table")
e := &XSelectTableExec{
table: table,
ctx: b.ctx,
tablePlan: v,
}
where := conditionsToPBExpression(v.FilterConditions...)
if xapi.SupportExpression(client, where) {
e.where = where
return e
}
return b.buildFilter(e, v.FilterConditions)
}

e := &TableScanExec{
t: table,
fields: v.Fields(),
Expand Down Expand Up @@ -150,7 +179,32 @@ func (b *executorBuilder) buildDeallocate(v *plan.Deallocate) Executor {
}

func (b *executorBuilder) buildIndexScan(v *plan.IndexScan) Executor {
txn, err := b.ctx.GetTxn(false)
if err != nil {
b.err = err
return nil
}
tbl, _ := b.is.TableByID(v.Table.ID)
client := txn.GetClient()
var memDB bool
switch v.Fields()[0].DBName.L {
case "information_schema", "performance_schema":
memDB = true
}
if !memDB && client.SupportRequestType(kv.ReqTypeIndex, 0) && txn.IsReadOnly() {
log.Debug("xapi select index")
e := &XSelectIndexExec{
table: tbl,
ctx: b.ctx,
indexPlan: v,
}
where := conditionsToPBExpression(v.FilterConditions...)
if xapi.SupportExpression(client, where) {
e.where = where
return e
}
return b.buildFilter(e, v.FilterConditions)
}
var idx *column.IndexedCol
for _, val := range tbl.Indices() {
if val.IndexInfo.Name.L == v.Index.Name.L {
Expand Down
Loading

0 comments on commit 0157bcd

Please sign in to comment.