From f3a735edca6835b82dd69d6e3c82ad53e9f2366c Mon Sep 17 00:00:00 2001 From: sravichandran Date: Mon, 20 Jul 2026 10:56:15 +0530 Subject: [PATCH 1/2] Fix PointInSetQuery#ramBytesUsed to include retained bounds arrays --- lucene/CHANGES.txt | 3 +++ .../apache/lucene/search/PointInSetQuery.java | 4 +++- .../apache/lucene/search/TestPointQueries.java | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 979f742b3082..fe51f3e48680 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -386,6 +386,9 @@ Bug Fixes * GITHUB#16389: Fix double-counting of the underlying Automaton in AutomatonQuery#ramBytesUsed. (Sasilekha R) +* GITHUB#16405: PointInSetQuery#ramBytesUsed now accounts for the retained + lowerPoint and upperPoint bounds arrays. (Sasilekha R) + * GITHUB#16367: HNSW graph construction now periodically checks whether the surrounding merge has been aborted, so IndexWriter#rollback and abortMerges no longer block until the entire graph is built. (Jeho Jeong) diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java index 431c5b87b25d..90bca4e8def7 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java @@ -136,7 +136,9 @@ protected PointInSetQuery(String field, int numDims, int bytesPerDim, Stream pac ramBytesUsed = BASE_RAM_BYTES + RamUsageEstimator.sizeOfObject(field) - + RamUsageEstimator.sizeOfObject(sortedPackedPoints); + + RamUsageEstimator.sizeOfObject(sortedPackedPoints) + + RamUsageEstimator.sizeOfObject(lowerPoint) + + RamUsageEstimator.sizeOfObject(upperPoint); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java index a61adf527fff..ef18a0cff1e1 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java @@ -67,6 +67,7 @@ import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util.RamUsageEstimator; import org.apache.lucene.util.bkd.BKDConfig; import org.junit.BeforeClass; @@ -2630,4 +2631,21 @@ protected String toString(byte[] point) { }); assertEquals("values are out of order: saw [2] before [1]", expected.getMessage()); } + + public void testRamBytesUsedIncludesBoundsArrays() { + // The constructor allocates lowerPoint/upperPoint and retains them for the whole + // lifetime of the query (scorerSupplier uses them for a per-segment pre-check). + // Both must contribute to ramBytesUsed(). + PointInSetQuery q = + (PointInSetQuery) BinaryPoint.newSetQuery("f", new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); + assertNotNull(q.lowerPoint); + assertNotNull(q.upperPoint); + long expected = + RamUsageEstimator.shallowSizeOfInstance(PointInSetQuery.class) + + RamUsageEstimator.sizeOfObject(q.field) + + RamUsageEstimator.sizeOfObject(q.sortedPackedPoints) + + RamUsageEstimator.sizeOfObject(q.lowerPoint) + + RamUsageEstimator.sizeOfObject(q.upperPoint); + assertEquals(expected, q.ramBytesUsed()); + } } From aa5e994777677e91b3f3aaaa13174274ae5cb257 Mon Sep 17 00:00:00 2001 From: sravichandran Date: Mon, 20 Jul 2026 12:52:48 +0530 Subject: [PATCH 2/2] Add RamUsageTester cross-check for PointInSetQuery#ramBytesUsed --- .../lucene/search/TestPointQueries.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java index ef18a0cff1e1..2b3a91b55bf7 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java @@ -62,6 +62,7 @@ import org.apache.lucene.tests.index.RandomIndexWriter; import org.apache.lucene.tests.search.FixedBitSetCollector; import org.apache.lucene.tests.util.LuceneTestCase; +import org.apache.lucene.tests.util.RamUsageTester; import org.apache.lucene.tests.util.TestUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; @@ -2648,4 +2649,22 @@ public void testRamBytesUsedIncludesBoundsArrays() { + RamUsageEstimator.sizeOfObject(q.upperPoint); assertEquals(expected, q.ramBytesUsed()); } + + public void testRamBytesUsedMatchesActualWithinTolerance() { + // Independent cross-check against a full object-graph walk; guards against the + // case where the byte-exact test and the implementation drift together. + // Mirrors TestTermInSetQuery#testRamBytesUsed (many entries, 5% margin). + final int numPoints = 10000 + random().nextInt(1000); + final byte[][] values = new byte[numPoints][]; + for (int i = 0; i < numPoints; i++) { + values[i] = new byte[8]; + random().nextBytes(values[i]); + } + PointInSetQuery query = (PointInSetQuery) BinaryPoint.newSetQuery("f", values); + final long actualRamBytesUsed = RamUsageTester.ramUsed(query); + final long expectedRamBytesUsed = query.ramBytesUsed(); + // error margin within 5% + assertEquals( + (double) expectedRamBytesUsed, (double) actualRamBytesUsed, actualRamBytesUsed / 20.d); + } }