Repository navigation
logdb: range-scan every address-less criterion and cap open-ended spans - #1694
Conversation
Every event index except event_i0 has address between its topic columns and seq, so any criterion without an address (topic1-only, topic0+topic1, topic4, ...) reads all its matching entries chain-wide, not just topic0-only ones. Write every topic term with the unary plus when such a criterion meets a narrow range. A block range with no "to" reaches logdb as To = MaxBlockNumber and was treated as wide. Cap To at the newest block holding events when deciding the plan; the query still binds the requested bounds, so results are unchanged. The equivalence test now takes its index path from buildEventFilterSubQuery with the scan disabled instead of a hand copy.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
04165ec to
65cc4dc
Compare
|
Measured both parts of this PR against a mainnet
So extending the rule from topic0-only to every address-less criterion is worth it: every hot value goes from a guaranteed timeout to milliseconds, including I pushed 65cc4dc on top: open-ended and oversized block ranges are now capped at Raw logs and plans: single-block and 100k-window queries for all shapes, plus the discovery queries for the hot/sparse values, are kept locally if anyone wants them. |
Description
Stacked on #1693. Merge into that branch or cherry-pick.
#1693 evaluates narrow topic0-only criteria by a
seqrange scan. Two cases still get the chain-wide plan:ConvertRangemaps an omittedtotoMaxBlockNumber, so{from: head-10}counts as a ~268M-block span and keepsevent_i1 (topic0=?)+ temp b-tree.narrowRangenow capsToat the newest block holding events (MAX(seq)) for the plan decision. It is only queried when the requested span exceeds the bound and a criterion has no address. The SQL still binds the requested bounds, so results cannot change.event_i0hasaddressbetween its topic columns andseq, sotopic1,topic4andtopic0+topicNwithout an address read all matching entries chain-wide (event_i2 (topic1=? AND topic0=?)+ temp b-tree). The rule is nowc.Address == nil, and every topic term is written with the unary plus.Synthetic DB (8M events, 70% one topic0, warm cache):
{last-10, MaxBlockNumber}Fixes # (none)
Type of change
How Has This Been Tested?
TestEventQueryPlanPerCriteriaShape: addstopic1,topic4,topic0+topic1/2/3shapes, which take the scan plan when narrow and keep their index when wide or unboundedTestNarrowRange: the cap for nil, inverted and narrow ranges, open-ended ranges on both sides of the bound, a start past the newest block, and an empty DBTestEventFilterScanEquivalence: addstopic0+topic1,topic1, mixed address/address-less sets and a{5, MaxBlockNumber}range. The index path is now built bybuildEventFilterSubQuery(f, false)instead of a hand copy.topic0+topic1cases with the old predicate)./logdb/...and./api/...pass; golangci-lint v2.12.2,modernize -testandgo mod tidycleanTest Configuration:
Checklist: