From dd871d54994eed29e1c8c8e7fcf943ee1cda2d22 Mon Sep 17 00:00:00 2001 From: Alan Paxton Date: Tue, 19 Dec 2023 14:31:50 +0000 Subject: [PATCH] [optimize] save 1 sort of result sets 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. --- .../java/org/exist/indexing/range/RangeIndexWorker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extensions/indexes/range/src/main/java/org/exist/indexing/range/RangeIndexWorker.java b/extensions/indexes/range/src/main/java/org/exist/indexing/range/RangeIndexWorker.java index 1f397c32407..c0c0374b4ab 100644 --- a/extensions/indexes/range/src/main/java/org/exist/indexing/range/RangeIndexWorker.java +++ b/extensions/indexes/range/src/main/java/org/exist/indexing/range/RangeIndexWorker.java @@ -518,7 +518,7 @@ private void write() { public NodeSet query(int contextId, DocumentSet docs, NodeSet contextSet, List qnames, AtomicValue[] keys, RangeIndex.Operator operator, int axis) throws IOException, XPathException { return index.withSearcher(searcher -> { List definedIndexes = getDefinedIndexes(qnames); - NodeSet resultSet = new NewArrayNodeSet(); + NodeSet resultSet = null; for (QName qname : definedIndexes) { Query query; String field = LuceneUtil.encodeQName(qname, index.getBrokerPool().getSymbols()); @@ -534,7 +534,12 @@ public NodeSet query(int contextId, DocumentSet docs, NodeSet contextSet, List