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

Avoid using tipb.KeyRange #1685

Merged
merged 4 commits into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
*: Avoid decode values when only need handle
  • Loading branch information
shenli committed Sep 4, 2016
commit 890f603234f604f21e6cbb57b2187f6066bcf55d
1 change: 1 addition & 0 deletions executor/executor_xapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ func (e *XSelectIndexExec) nextForDoubleRead() (*Row, error) {
if err != nil {
return nil, errors.Trace(err)
}
idxResult.IgnoreData()
idxResult.Fetch()

// Use a background goroutine to fetch index, put the result in e.tasks.
Expand Down
3 changes: 1 addition & 2 deletions store/localstore/local_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ func (rs *localRegion) getRowsFromAgg(ctx *selectContext) ([]*tipb.Row, error) {
return rows, nil
}

// extractKVRanges extracts kv.KeyRanges slice from a SelectRequest, and also returns if it is in descending order.
// func (rs *localRegion) extractKVRanges(sel *tipb.SelectRequest) (kvRanges []kv.KeyRange, desc bool) {
// extractKVRanges extracts kv.KeyRanges slice from ctx.keyRanges, and also returns if it is in descending order.
func (rs *localRegion) extractKVRanges(ctx *selectContext) (kvRanges []kv.KeyRange, desc bool) {
sel := ctx.sel
for _, kran := range ctx.keyRanges {
Expand Down
53 changes: 34 additions & 19 deletions xapi/xapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type SelectResult interface {
// Fetch fetches partial results from client.
// The caller should call SetFields() before call Fetch().
Fetch()
// IgnoreData sets ignore data attr to true.
// For index double scan, we do not need row data when scanning index.
IgnoreData()
}

// PartialResult is the result from a single region server.
Expand All @@ -62,10 +65,11 @@ type PartialResult interface {

// SelectResult is used to get response rows from SelectRequest.
type selectResult struct {
index bool
aggregate bool
fields []*types.FieldType
resp kv.Response
index bool
aggregate bool
fields []*types.FieldType
resp kv.Response
ignoreData bool

results chan PartialResult
done chan error
Expand All @@ -87,11 +91,12 @@ func (r *selectResult) fetch() {
return
}
pr := &partialResult{
index: r.index,
fields: r.fields,
reader: reader,
aggregate: r.aggregate,
done: make(chan error),
index: r.index,
fields: r.fields,
reader: reader,
aggregate: r.aggregate,
ignoreData: r.ignoreData,
done: make(chan error),
}
go pr.fetch()
r.results <- pr
Expand Down Expand Up @@ -119,19 +124,24 @@ func (r *selectResult) SetFields(fields []*types.FieldType) {
r.fields = fields
}

func (r *selectResult) IgnoreData() {
r.ignoreData = true
}

// Close closes SelectResult.
func (r *selectResult) Close() error {
return r.resp.Close()
}

// partialResult represents a subset of select result.
type partialResult struct {
index bool
aggregate bool
fields []*types.FieldType
reader io.ReadCloser
resp *tipb.SelectResponse
cursor int
index bool
aggregate bool
fields []*types.FieldType
reader io.ReadCloser
resp *tipb.SelectResponse
cursor int
ignoreData bool

done chan error
fetched bool
Expand All @@ -156,6 +166,8 @@ func (pr *partialResult) fetch() {
pr.done <- nil
}

var dummyData = make([]types.Datum, 0)

// Next returns the next row of the sub result.
// If no more row to return, data would be nil.
func (pr *partialResult) Next() (handle int64, data []types.Datum, err error) {
Expand All @@ -172,15 +184,18 @@ func (pr *partialResult) Next() (handle int64, data []types.Datum, err error) {
return 0, nil, nil
}
row := pr.resp.Rows[pr.cursor]
data, err = tablecodec.DecodeValues(row.Data, pr.fields, pr.index)
if err != nil {
return 0, nil, errors.Trace(err)
if !pr.ignoreData {
data, err = tablecodec.DecodeValues(row.Data, pr.fields, pr.index)
if err != nil {
return 0, nil, errors.Trace(err)
}
}
if data == nil {
// When no column is referenced, the data may be nil, like 'select count(*) from t'.
// In this case, we need to create a zero length datum slice,
// as caller will check if data is nil to finish iteration.
data = make([]types.Datum, 0)
// data = make([]types.Datum, 0)
data = dummyData
}
if !pr.aggregate {
handleBytes := row.GetHandle()
Expand Down