-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add support for scanning multiple spans for a single index. #2293
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,14 +59,18 @@ func (q *qvalue) String() string { | |
type qvalMap map[ColumnID]*qvalue | ||
type colKindMap map[ColumnID]ColumnType_Kind | ||
|
||
type span struct { | ||
start proto.Key | ||
end proto.Key | ||
} | ||
|
||
// A scanNode handles scanning over the key/value pairs for a table and | ||
// reconstructing them into rows. | ||
type scanNode struct { | ||
txn *client.Txn | ||
desc *TableDescriptor | ||
index *IndexDescriptor | ||
startKey proto.Key | ||
endKey proto.Key | ||
spans []span | ||
visibleCols []ColumnDescriptor | ||
isSecondaryIndex bool | ||
reverse bool | ||
|
@@ -231,22 +235,39 @@ func (n *scanNode) initScan() bool { | |
return true | ||
} | ||
|
||
// Retrieve all of the keys that start with our index key prefix. | ||
if len(n.startKey) == 0 { | ||
n.startKey = proto.Key(MakeIndexKeyPrefix(n.desc.ID, n.index.ID)) | ||
} | ||
if len(n.endKey) == 0 { | ||
n.endKey = n.startKey.PrefixEnd() | ||
if len(n.spans) == 0 { | ||
// If no spans were specified retrieve all of the keys that start with our | ||
// index key prefix. | ||
start := proto.Key(MakeIndexKeyPrefix(n.desc.ID, n.index.ID)) | ||
n.spans = append(n.spans, span{ | ||
start: start, | ||
end: start.PrefixEnd(), | ||
}) | ||
} | ||
|
||
// Retrieve all the spans. | ||
b := &client.Batch{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's going to be a subtle interaction with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you worried about? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a case like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm aware of that. I thought the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, github hid that TODO from me. Yep, that's adequate, thanks. |
||
if n.reverse { | ||
n.kvs, n.err = n.txn.ReverseScan(n.startKey, n.endKey, 0) | ||
for i := len(n.spans) - 1; i >= 0; i-- { | ||
b.ReverseScan(n.spans[i].start, n.spans[i].end, 0) | ||
} | ||
} else { | ||
n.kvs, n.err = n.txn.Scan(n.startKey, n.endKey, 0) | ||
for i := 0; i < len(n.spans); i++ { | ||
b.Scan(n.spans[i].start, n.spans[i].end, 0) | ||
} | ||
} | ||
if n.err != nil { | ||
if n.err = n.txn.Run(b); n.err != nil { | ||
return false | ||
} | ||
|
||
for _, result := range b.Results { | ||
if n.kvs == nil { | ||
n.kvs = result.Rows | ||
} else { | ||
n.kvs = append(n.kvs, result.Rows...) | ||
} | ||
} | ||
|
||
// Prepare our index key vals slice. | ||
if n.valTypes, n.err = makeKeyVals(n.desc, n.columnIDs); n.err != nil { | ||
return false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query is usually no longer very slow, but I still sometimes see log messages like:
I0828 15:07:06.299984 34037 examples/sql_bank/main.go:61 SELECT id, balance FROM accounts WHERE id IN (130, 204) took 3.059484793s