Repository navigation
Conversation
When a vertex step filters results after reading (e.g. out().has(k, v)), its limit is reset to NO_LIMIT, so the backend merged up to 500 edges of an owner vertex into the first entry and the edge cache probed up to 101 edges before the first result was returned. Add Query.batchSizeHint(): the number of results the caller expects to need. It never limits the results. HugeVertexStep keeps a limit it can't push down as the hint, BinaryEntryIterator reads the first entry at the hinted size and doubles it up to INLINE_BATCH_SIZE, and CachedGraphTransaction doesn't read past the hint to fill the edge cache. Queries without a hint behave as before.
not(), filter(), where(traversal), and() and or() only call hasNext() on their child traversals, but HugeVertexStep read edges as if every result was needed. On a vertex with 2,000 edges of one label, not(out(label).has(k, v)) read about 500 edges per start vertex. HugeVertexStepStrategy now marks a HugeVertexStep that ends such a child traversal with a batch size hint of 1. A step followed by any other step (count(), path(), tree(), order(), range() and so on) is left unchanged. Fixes apache#3480
imbajin
left a comment
There was a problem hiding this comment.
Score: 8.0/10 · Confidence: medium
Blocking: no
Summary
No new actionable issues found in the batch hint and cache changes.
Evidence
Reviewed hint propagation, iterator batching, cache completeness, traversal strategy, regression tests and the available discussion with five independent lanes.
Validation notes
No tests or performance benchmarks were run independently; distributed backend behavior remains unverified and core CI is still running.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3486 +/- ##
============================================
+ Coverage 58.52% 58.62% +0.10%
- Complexity 2717 3105 +388
============================================
Files 779 780 +1
Lines 69439 69657 +218
Branches 9577 9609 +32
============================================
+ Hits 40637 40836 +199
- Misses 25108 25126 +18
- Partials 3694 3695 +1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bitflicker64
left a comment
There was a problem hiding this comment.
Blocking: no. Score: 9/10. Summary: batchSizeHint only changes how BinaryEntryIterator and the edge cache probe split reads, never the results, and the focused unit tests plus EdgeCoreTest pass on memory and RocksDB. Hinted existence checks on vertices with 2-100 edges stop filling the edge cache, as the PR body notes.
Purpose of the PR
not(),filter(),where(traversal),and()andor()only check whether their child traversal hasany result (
hasNext()). But when the child ends without(label).has(...)on a high-degree vertex,HugeGraph still read about 500 edges per start vertex before returning the first one:
HugeVertexStepdrops any limit whenhas()must be filtered after reading;BinaryEntryIteratormerges up toINLINE_BATCH_SIZE(500) columns into one entry before returning;CachedGraphTransaction.fetchEdgeBatchreads up to 101 edges to decide whether to cache the result.On RocksDB with 2,000 edges per vertex,
not(out(high).has(k, v))took ~21 ms per vertex, versus~1 ms for the same check on a low-degree label.
Main Changes
Query.batchSizeHint()(hugegraph-struct): a new, optional hint for how many results the callerexpects to need. It never limits results. It defaults to
NO_LIMIT, is copied incopyBasic(),and is not part of
equals/hashCode.BinaryEntryIterator: when the query has a hint < 500, the first entry merges onlyhintcolumns,and each later entry doubles in size until it reaches 500. Without a hint, behaviour is unchanged.
CachedGraphTransaction.fetchEdgeBatch: the cache probe reads at mostmin(hint, 101)edges, andcaches only when the source is exhausted, so a partial result is never cached. Without a hint, behaviour is unchanged.
HugeVertexStep.constructEdgesQuery: when a limit can't be pushed down because of filtering,it becomes a hint instead of being dropped (
out().has().limit(n)benefits as well).HugeVertexStepStrategy: aHugeVertexStepthat is the end step of a local child ofNotStep/TraversalFilterStep/ConnectiveStepgets hint 1. If anything follows the step(
count(),path(),tree(),order(),range(), more steps), or the step sits inwhere()with labels,local(),optional()or at the root, it is not hinted.A hint is used instead of
limit(1)because a hard limit fails with uncommitted records in thetransaction ("not allowed to query with offset/limit when there are uncommitted records"). It would
also be wrong for
HugeVertexStepByBatchIN-queries that cover several owner vertices, and thebackend can't apply a limit before
has()filtering anyway.Verifying these changes
unit-test(memory, 1489 tests) andcore-test(memory and rocksdb, 1036 tests each) pass, including the paging test from [Bug] Paging returns the page-boundary record twice when limit is a multiple of 500 (BinaryEntryIterator; RocksDB and HStore) #3191.
BinaryBackendEntryTest#testEntryIteratorReadsSmallBatchesFirstWithHint: entry sizes[10]with no hint,[1, 2, 4, 3]with hint 1, and[10]with hint 501CachedGraphTransactionTest#testHintedEdgeBatchProbesOnlyHintedEdgesForCacheTraversalUtilOptimizeTest#testVertexStepStrategyHintsExistenceCheck,#testVertexStepStrategyNotHintAllResultsNeeded,#testVertexStepStrategyKeepsLimitWithHintEdgeCoreTest#testQueryExistenceOfAdjacentVerticesOverBatchSize: a vertex with 600 edges checkedwith not/filter/where/and/or, plus checks for the hint
Benchmark (RocksDB, 50 start vertices × 2,000
highedges, in-JVM median per query, ms):g.V().hasLabel(..).filter(not(<child>))childout(low).has(keep, false)out(high).has(keep, false)out(high)outE(high)out(high).has(keep, false).limit(1)out(high).has(keep, false), no neighbor matches (reads all edges)out(..).has(..)(2–100 edges, cache-populate trade-off)out(high).count()(not hinted)End-to-end HTTP median for the issue query: 28.3 ms → 6.6 ms.
Does this PR potentially affect the following parts?
Queryin hugegraph-struct (shared with hstore;backends that don't use it ignore it). Hinted queries that match 2–100 edges no longer
populate the edge cache, but they still read from it.
Documentation Status
Doc - TODODoc - DoneDoc - No Need: no user-visible documentation is affected.