VGalaxies commented on code in PR #2994:
URL: https://github.com/apache/hugegraph/pull/2994#discussion_r3400810201
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java:
##########
@@ -657,6 +664,250 @@ private IdHolder doIndexQuery(IndexLabel indexLabel,
ConditionQuery query) {
}
}
+ private boolean needHstoreRangeIndexOrder(IndexLabel indexLabel) {
+ return this.store().provider().isHstore() &&
+ indexLabel.indexType().isRange();
+ }
+
+ private IdHolder doHstoreRangeIndexQuery(IndexLabel indexLabel,
+ ConditionQuery query) {
+ if (!query.paging()) {
+ if (query.noLimitAndOffset()) {
+ return this.doIndexQueryBatch(indexLabel, query);
+ }
+ Set<Id> ids = this.querySortedRangeIndexIds(indexLabel, query);
+ return this.newSortedRangeIndexBatchHolder(query, ids);
+ }
+ return new SortedRangePagingIdHolder(query, q -> {
+ return this.querySortedRangeIndexPage(indexLabel, q);
+ });
+ }
+
+ private BatchIdHolder newSortedRangeIndexBatchHolder(ConditionQuery query,
+ Set<Id> ids) {
+ return new SortedRangeBatchIdHolder(query, ids);
+ }
+
+ private Set<Id> querySortedRangeIndexIds(IndexLabel indexLabel,
+ ConditionQuery query) {
+ List<HugeIndex> indexes = this.querySortedRangeIndexes(indexLabel,
+ query);
+ Set<Id> ids = InsertionOrderUtil.newSet();
+ for (HugeIndex index : indexes) {
+ ids.addAll(index.elementIds());
+ Query.checkForceCapacity(ids.size());
+ }
+ return ids;
+ }
+
+ private PageIds querySortedRangeIndexPage(IndexLabel indexLabel,
+ ConditionQuery query) {
+ List<HugeIndex> indexes = this.querySortedRangeIndexes(indexLabel,
+ query);
+ Set<Id> allIds = InsertionOrderUtil.newSet();
+ for (HugeIndex index : indexes) {
+ allIds.addAll(index.elementIds());
+ Query.checkForceCapacity(allIds.size());
+ }
+ if (allIds.isEmpty()) {
+ return PageIds.EMPTY;
+ }
+
+ int start = 0;
+ if (!query.page().isEmpty()) {
+ start = PageState.fromString(query.page()).offset();
+ }
+ if (start >= allIds.size()) {
+ return PageIds.EMPTY;
+ }
+
+ long total = allIds.size();
+ long end = query.noLimit() ? total :
+ Math.min(total, (long) start + query.limit());
+ Set<Id> pageIds = CollectionUtil.subSet(allIds, start, (int) end);
+ if (pageIds.isEmpty()) {
+ return PageIds.EMPTY;
+ }
+
+ int next = (int) end;
+ PageState pageState;
+ if (next < total) {
+ pageState = new PageState(new byte[]{1}, next, pageIds.size());
+ } else {
+ pageState = new PageState(PageState.EMPTY_BYTES, 0,
+ pageIds.size());
+ }
+ return new PageIds(pageIds, pageState);
+ }
+
+ private List<HugeIndex> querySortedRangeIndexes(IndexLabel indexLabel,
+ ConditionQuery query) {
+ List<HugeIndex> indexes = new ArrayList<>();
+ Iterator<BackendEntry> entries = null;
+ String spaceGraph = this.params()
+ .graph().spaceGraphName();
+ LockUtil.Locks locks = new LockUtil.Locks(spaceGraph);
+ ConditionQuery scanQuery = query.copy();
Review Comment:
**Major: HStore range-index paging discards backend bounds**
`hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java:750`
**Evidence**
- `doHstoreRangeIndexQuery()` sends every HStore range-index query with
paging or limit/offset through `querySortedRangeIndexIds/Page()`, and
`querySortedRangeIndexes()` copies the query then clears `page`, resets
`offset` to `0`, and sets `limit(Query.NO_LIMIT)` before calling
`super.query(scanQuery)`.
**Impact**
- A range-index query such as `limit(1)` or each page request can scan,
materialize, and sort the entire matching range under index-label locks, up to
force-capacity checks, instead of letting the backend enforce paging/limit. On
large HStore deployments this can turn normal paginated queries into timeouts,
capacity exceptions, or memory pressure.
**Requested fix**
- Preserve backend range paging/limit semantics for HStore, or implement a
bounded ordered paging path that fetches only enough index rows for the
requested page instead of clearing page/limit and sorting the full match set in
memory.
--
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]