Kv: drop double-scan in kv_idx_lower_bound on miss#333
Open
heifner wants to merge 1 commit into
Open
Conversation
When the secondary-index seek misses inside (code, table_id) -- either the index ended or landed past our (code, table_id) pair -- the old code issued a second lower_bound((code, table_id)) just to decide whether the table is empty. All rows of (code, table_id), if any, must lie strictly before the first-miss iterator, so the table is non-empty iff prev(itr) is in (code, table_id), with itr == idx.begin() short-circuiting to "no rows before." Return value and slot allocation are bit-identical for every input; this saves a B-tree hop per end-of-range secondary scan. Pure host-side optimization, not a consensus change -- contracts cannot observe a difference beyond CPU time, which is subjective in Sysio. Covered by existing kv_api_tests (idx_lower_bound + testidxempty for the empty-table -1 path) and the kv_intrinsic_probe_tests suite via PR #308 (lbpast + lbempty probes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apply_context::kv_idx_lower_boundissued a secondlower_bound((code, table_id))after the keyed seek missed, just to detect whether the table had any rows at all. Replace with astd::prev(itr)peek guarded byitr != idx.begin(). When the seek misses inside(code, table_id), all rows of the table (if any) lie strictly beforeitrin the index, so the table is non-empty iffprev(itr)is in our(code, table_id). Theitr == begin()guard covers both the empty-index case (begin() == end() == itr) and the "lower_bound landed on the very first row of a later table" case.Consensus
Pure host-side optimization. Return value and slot allocation are bit-identical for every input. The only thing that changes is the number of B-tree hops on the miss path. CPU time is subjective in Sysio, so contracts cannot observe a difference.