-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
save a key comparison in block seeks #6646
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,31 +653,27 @@ void BlockIter<TValue>::ScanAfterBinarySeek(const Slice& target, uint32_t index, | |
bool is_index_key_result, | ||
const Comparator* comp) { | ||
// Linear search (within restart block) for first key >= target | ||
if (is_index_key_result) { | ||
SeekToRestartPoint(index); | ||
Next(); | ||
} else { | ||
SeekToRestartPoint(index); | ||
SeekToRestartPoint(index); | ||
Next(); | ||
if (!is_index_key_result) { | ||
uint32_t max_offset; | ||
if (index + 1 < num_restarts_) { | ||
// We are in a non-last restart interval. Since `BinarySeek()` guarantees | ||
// the next restart key is strictly greater than `target`, we can | ||
// terminate upon reaching it without any additional key comparison. | ||
max_offset = GetRestartPoint(index + 1); | ||
} else { | ||
max_offset = restarts_; | ||
// We are in the last restart interval. The while-loop will terminate by | ||
// `Valid()` returning false upon advancing past the block's last key. | ||
max_offset = port::kMaxUint32; | ||
} | ||
bool first = true; | ||
while (true) { | ||
Next(); | ||
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. Can we just use 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. It's making use of polymorphism here -- |
||
if (!Valid()) { | ||
break; | ||
} | ||
if (first) { | ||
// Skip the comparison on the first key since we already know from | ||
// the binary search that it's less than target. | ||
first = false; | ||
} else if (current_ == max_offset) { | ||
// We already know from the binary search that this key is >= target. | ||
// Elide the key comparison. | ||
assert(comp->Compare(applied_key_.UpdateAndGetKey(), target) >= 0); | ||
if (current_ == max_offset) { | ||
assert(comp->Compare(applied_key_.UpdateAndGetKey(), target) > 0); | ||
break; | ||
} else if (comp->Compare(applied_key_.UpdateAndGetKey(), target) >= 0) { | ||
break; | ||
|
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.
A comment here might help. It took me a little while to figure out that this
Next()
actually doesn't advance to the next key, but just ends up decoding the key at the restart point we seek'd to.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.
Agree, done.