kccrcodes opened a new pull request, #3486:
URL: https://github.com/apache/hugegraph/pull/3486

   ## Purpose of the PR
   
   - close #3480
   
   `not()`, `filter()`, `where(traversal)`, `and()` and `or()` only check 
whether their child traversal has
   any result (`hasNext()`). But when the child ends with `out(label).has(...)` 
on a high-degree vertex,
   HugeGraph still read about 500 edges per start vertex before returning the 
first one:
   
   1. `HugeVertexStep` drops any limit when `has()` must be filtered after 
reading;
   2. `BinaryEntryIterator` merges up to `INLINE_BATCH_SIZE` (500) columns into 
one entry before returning;
   3. `CachedGraphTransaction.fetchEdgeBatch` reads 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 caller
     expects to need. It **never limits results**. It defaults to `NO_LIMIT`, 
is copied in `copyBasic()`,
     and is not part of `equals/hashCode`.
   - `BinaryEntryIterator`: when the query has a hint < 500, the first entry 
merges only `hint` columns,
     and each later entry doubles in size until it reaches 500. Without a hint, 
behaviour is unchanged.
   - `CachedGraphTransaction.fetchEdgeBatch`: the cache probe reads at most 
`min(hint, 101)` edges, and
     caches 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`: a `HugeVertexStep` that is the **end step** of a 
local child of
     `NotStep`/`TraversalFilterStep`/`ConnectiveStep` gets hint 1. If anything 
follows the step
     (`count()`, `path()`, `tree()`, `order()`, `range()`, more steps), or the 
step sits in
     `where()` 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 the
   transaction ("not allowed to query with offset/limit when there are 
uncommitted records"). It would
   also be wrong for `HugeVertexStepByBatch` IN-queries that cover several 
owner vertices, and the
   backend can't apply a limit before `has()` filtering anyway.
   
   ## Verifying these changes
   
   - [ ] Trivial rework / code cleanup without any test coverage. (No Need)
   - [x] Already covered by existing tests: full `unit-test` (memory, 1489 
tests) and `core-test`
         (memory and rocksdb, 1036 tests each) pass, including the paging test 
from #3191.
   - [x] Need tests and can be verified as follows:
       - 
`BinaryBackendEntryTest#testEntryIteratorReadsSmallBatchesFirstWithHint`: entry 
sizes
         `[10]` with no hint, `[1, 2, 4, 3]` with hint 1, and `[10]` with hint 
501
       - 
`CachedGraphTransactionTest#testHintedEdgeBatchProbesOnlyHintedEdgesForCache`
       - `TraversalUtilOptimizeTest#testVertexStepStrategyHintsExistenceCheck`,
         `#testVertexStepStrategyNotHintAllResultsNeeded`, 
`#testVertexStepStrategyKeepsLimitWithHint`
       - `EdgeCoreTest#testQueryExistenceOfAdjacentVerticesOverBatchSize`: a 
vertex with 600 edges checked
         with not/filter/where/and/or, plus checks for the hint
   
   Benchmark (RocksDB, 50 start vertices × 2,000 `high` edges, in-JVM median 
per query, ms):
   
   | `g.V().hasLabel(..).filter(not(<child>))` child | master | this PR |
   |---|---|---|
   | `out(low).has(keep, false)` | 0.67 | 0.73 |
   | **`out(high).has(keep, false)`** | **20.83** | **1.25** |
   | `out(high)` | 20.93 | 1.78 |
   | `outE(high)` | 21.48 | 1.04 |
   | `out(high).has(keep, false).limit(1)` | 21.48 | 1.38 |
   | `out(high).has(keep, false)`, no neighbor matches (reads all edges) | 326 
| 318–323 |
   | low-degree `out(..).has(..)` (2–100 edges, cache-populate trade-off) | 1.9 
| 2.4–2.7 |
   | root `out(high).count()` (not hinted) | 103 | 104–117 |
   
   End-to-end HTTP median for the issue query: 28.3 ms → 6.6 ms.
   
   ## Does this PR potentially affect the following parts?
   
   - [ ]  Dependencies
   - [ ]  Modify configurations
   - [ ]  The public API
   - [x]  Other affects (typed here): adds a field to `Query` in 
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.
   - [ ]  Nope
   
   ## Documentation Status
   
   - [ ] `Doc - TODO`
   - [ ] `Doc - Done`
   - [x] `Doc - No Need`: no user-visible documentation is affected.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to