Use ByteArrayComparator for PointInSetQuery#MergePointVisitor (#11876)

This commit is contained in:
gf2121 2022-10-26 13:39:32 +08:00 committed by GitHub
parent 50261de406
commit 05bd83dfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View File

@ -150,6 +150,9 @@ Optimizations
given field to match a term (rather than all docs in a segment). This is consistent with given field to match a term (rather than all docs in a segment). This is consistent with
MultiTermQueryConstantScoreWrapper. (Greg Miller) MultiTermQueryConstantScoreWrapper. (Greg Miller)
* GITHUB#11876: Use ByteArrayComparator to speed up PointInSetQuery in single dimension case.
(Guo Feng)
Other Other
--------------------- ---------------------
* LUCENE-10423: Remove usages of System.currentTimeMillis() from tests. (Marios Trivyzas) * LUCENE-10423: Remove usages of System.currentTimeMillis() from tests. (Marios Trivyzas)

View File

@ -214,7 +214,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
private final DocIdSetBuilder result; private final DocIdSetBuilder result;
private TermIterator iterator; private TermIterator iterator;
private BytesRef nextQueryPoint; private BytesRef nextQueryPoint;
private final BytesRef scratch = new BytesRef(); private final ByteArrayComparator comparator;
private final PrefixCodedTerms sortedPackedPoints; private final PrefixCodedTerms sortedPackedPoints;
private DocIdSetBuilder.BulkAdder adder; private DocIdSetBuilder.BulkAdder adder;
@ -222,7 +222,7 @@ public abstract class PointInSetQuery extends Query implements Accountable {
throws IOException { throws IOException {
this.result = result; this.result = result;
this.sortedPackedPoints = sortedPackedPoints; this.sortedPackedPoints = sortedPackedPoints;
scratch.length = bytesPerDim; this.comparator = ArrayUtil.getUnsignedComparator(bytesPerDim);
this.iterator = this.sortedPackedPoints.iterator(); this.iterator = this.sortedPackedPoints.iterator();
nextQueryPoint = iterator.next(); nextQueryPoint = iterator.next();
} }
@ -257,9 +257,8 @@ public abstract class PointInSetQuery extends Query implements Accountable {
} }
private boolean matches(byte[] packedValue) { private boolean matches(byte[] packedValue) {
scratch.bytes = packedValue;
while (nextQueryPoint != null) { while (nextQueryPoint != null) {
int cmp = nextQueryPoint.compareTo(scratch); int cmp = comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, packedValue, 0);
if (cmp == 0) { if (cmp == 0) {
return true; return true;
} else if (cmp < 0) { } else if (cmp < 0) {
@ -276,15 +275,15 @@ public abstract class PointInSetQuery extends Query implements Accountable {
@Override @Override
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
while (nextQueryPoint != null) { while (nextQueryPoint != null) {
scratch.bytes = minPackedValue; int cmpMin =
int cmpMin = nextQueryPoint.compareTo(scratch); comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, minPackedValue, 0);
if (cmpMin < 0) { if (cmpMin < 0) {
// query point is before the start of this cell // query point is before the start of this cell
nextQueryPoint = iterator.next(); nextQueryPoint = iterator.next();
continue; continue;
} }
scratch.bytes = maxPackedValue; int cmpMax =
int cmpMax = nextQueryPoint.compareTo(scratch); comparator.compare(nextQueryPoint.bytes, nextQueryPoint.offset, maxPackedValue, 0);
if (cmpMax > 0) { if (cmpMax > 0) {
// query point is after the end of this cell // query point is after the end of this cell
return Relation.CELL_OUTSIDE_QUERY; return Relation.CELL_OUTSIDE_QUERY;