Skip to content

Commit

Permalink
[optimise] save 1 sort of result sets
Browse files Browse the repository at this point in the history
Where there is a single defined index, adding the first result (which is returned sorted) to a new result set causes an unnecessary extra sort() of the result set.
  • Loading branch information
alanpaxton authored and adamretter committed Dec 1, 2024
1 parent 955c13b commit 7fbb96b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void write() {
public NodeSet query(int contextId, DocumentSet docs, NodeSet contextSet, List<QName> qnames, AtomicValue[] keys, RangeIndex.Operator operator, int axis) throws IOException, XPathException {
return index.withSearcher(searcher -> {
List<QName> definedIndexes = getDefinedIndexes(qnames);
NodeSet resultSet = new NewArrayNodeSet();
NodeSet resultSet = null;
for (QName qname : definedIndexes) {
Query query;
String field = LuceneUtil.encodeQName(qname, index.getBrokerPool().getSymbols());
Expand All @@ -534,7 +534,12 @@ public NodeSet query(int contextId, DocumentSet docs, NodeSet contextSet, List<Q
final short nodeType = qname.getNameType() == ElementValue.ATTRIBUTE ? Node.ATTRIBUTE_NODE : Node
.ELEMENT_NODE;

resultSet.addAll(doQuery(contextId, docs, contextSet, axis, searcher.searcher, nodeType, query, null));
final NodeSet indexedResultSet = doQuery(contextId, docs, contextSet, axis, searcher.searcher, nodeType, query, null);
if (resultSet == null) {
resultSet = indexedResultSet;
} else {
resultSet.addAll(indexedResultSet);
}
}
return resultSet;
});
Expand Down

0 comments on commit 7fbb96b

Please sign in to comment.