Skip to content

Commit

Permalink
fix: optimization to avoid load record from indexes that do not match…
Browse files Browse the repository at this point in the history
… the target class
  • Loading branch information
tglman committed Aug 21, 2023
1 parent 82b9e4c commit c375f90
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,22 @@ && handleClassWithIndexForSortOnly(
plan.chain(fetcher);
}

private int[] classClustersFiltered(
ODatabaseSession db, OClass clazz, Set<String> filterClusters) {
int[] ids = clazz.getClusterIds();
List<Integer> filtered = new ArrayList<>();
for (int id : ids) {
if (filterClusters.contains(db.getClusterNameById(id))) {
filtered.add(id);
}
}
int[] result = new int[filtered.size()];
for (int i = 0; i < filtered.size(); i++) {
result[i] = filtered.get(i);
}
return result;
}

private boolean handleClassAsTargetWithIndexedFunction(
OSelectExecutionPlan plan,
Set<String> filterClusters,
Expand Down Expand Up @@ -2025,8 +2041,9 @@ private boolean handleClassAsTargetWithIndexedFunction(
subPlan.chain(step);
int[] filterClusterIds = null;
if (filterClusters != null) {
filterClusterIds =
((ODatabaseDocumentInternal) ctx.getDatabase()).getClustersIds(filterClusters);
filterClusterIds = classClustersFiltered(ctx.getDatabase(), clazz, filterClusters);
} else {
filterClusterIds = clazz.getClusterIds();
}
subPlan.chain(new GetValueFromIndexEntryStep(ctx, filterClusterIds, profilingEnabled));
if (requiresMultipleIndexLookups(bestIndex.getKeyCondition())
Expand Down Expand Up @@ -2265,8 +2282,9 @@ private boolean handleClassWithIndexForSortOnly(
idx, orderType.equals(OOrderByItem.ASC), ctx, profilingEnabled));
int[] filterClusterIds = null;
if (filterClusters != null) {
filterClusterIds =
((ODatabaseDocumentInternal) ctx.getDatabase()).getClustersIds(filterClusters);
filterClusterIds = classClustersFiltered(ctx.getDatabase(), clazz, filterClusters);
} else {
filterClusterIds = clazz.getClusterIds();
}
plan.chain(new GetValueFromIndexEntryStep(ctx, filterClusterIds, profilingEnabled));
if (info.serverToClusters.size() == 1) {
Expand Down Expand Up @@ -2458,8 +2476,9 @@ private List<OExecutionStepInternal> handleClassAsTargetWithIndex(
profilingEnabled));
int[] filterClusterIds = null;
if (filterClusters != null) {
filterClusterIds =
((ODatabaseDocumentInternal) ctx.getDatabase()).getClustersIds(filterClusters);
filterClusterIds = classClustersFiltered(ctx.getDatabase(), clazz, filterClusters);
} else {
filterClusterIds = clazz.getClusterIds();
}
result.add(new GetValueFromIndexEntryStep(ctx, filterClusterIds, profilingEnabled));
if (requiresMultipleIndexLookups(desc.getKeyCondition()) || duplicateResultsForRecord(desc)) {
Expand Down

0 comments on commit c375f90

Please sign in to comment.