You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2026/04/02 16:18:23 UTC
(jackrabbit-oak) branch trunk updated: OAK-12171 Cost estimation for is (not) null checks are wrong (#2825)
This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 1e777e9aa7 OAK-12171 Cost estimation for is (not) null checks are wrong (#2825)
1e777e9aa7 is described below
commit 1e777e9aa7aa98c9b85c15f1288c96e260ee201d
Author: Thomas Mueller <th...@apache.org>
AuthorDate: Thu Apr 2 18:18:17 2026 +0200
OAK-12171 Cost estimation for is (not) null checks are wrong (#2825)
* OAK-12171 Cost estimation for is (not) null checks are wrong
* OAK-12171 Cost estimation for is (not) null checks are wrong
* OAK-12171 Cost estimation for is (not) null checks are wrong
* OAK-12171 Cost estimation for is (not) null checks are wrong
* OAK-12171 Cost estimation for is (not) null checks are wrong
* OAK-12171 Cost estimation for is (not) null checks are wrong
---
.../index/lucene/LuceneIndexProviderService.java | 5 +
.../oak/plugins/index/lucene/IndexPlannerTest.java | 5 +-
.../index/lucene/LuceneIndexPlannerCommonTest.java | 70 ++++---
.../index/elastic/ElasticIndexProviderService.java | 7 +
.../elastic/ElasticIndexPlannerCommonTest.java | 80 ++++----
.../index/search/FulltextIndexConstants.java | 12 ++
.../plugins/index/search/PropertyDefinition.java | 21 +++
.../search/spi/query/FulltextIndexPlanner.java | 54 +++++-
.../index/search/util/IndexDefinitionBuilder.java | 10 +
.../oak/plugins/index/IndexPlannerCommonTest.java | 203 ++++++++++++++++++++-
10 files changed, 381 insertions(+), 86 deletions(-)
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
index 09833d8214..f2876dc527 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
@@ -58,6 +58,8 @@ import org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderF
import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.TextExtractionStatsMBean;
+import org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner;
+import org.apache.jackrabbit.oak.spi.toggle.FeatureToggle;
import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
import org.apache.jackrabbit.oak.spi.commit.BackgroundObserver;
import org.apache.jackrabbit.oak.spi.commit.BackgroundObserverMBean;
@@ -369,6 +371,9 @@ public class LuceneIndexProviderService {
}
whiteboard = new OsgiWhiteboard(bundleContext);
+ oakRegs.add(whiteboard.register(FeatureToggle.class,
+ new FeatureToggle(FulltextIndexPlanner.FT_OAK_12171, FulltextIndexPlanner.FT_OAK_12171_DISABLE),
+ emptyMap()));
initializeIndexDir(bundleContext, config);
initializeExtractedTextCache(bundleContext, config, statisticsProvider);
tracker = createTracker(bundleContext, config);
diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
index c833146bf7..aa5d05b8c1 100644
--- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
+++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlannerTest.java
@@ -1337,12 +1337,13 @@ public class IndexPlannerTest {
assertEquals(1.0, plan.getCostPerExecution(), 0);
assertEquals(1.0, plan.getCostPerEntry(), 0);
- // Query on "foo" is not null
+ // Query on "foo" is not null: no explicit weight -> heuristic weight applied
filter = createFilter("nt:base");
filter.restrictProperty("foo", Operator.NOT_EQUAL, null);
planner = new FulltextIndexPlanner(node, "/test", filter, Collections.emptyList());
plan = planner.getPlan();
- assertEquals(numOfDocs, plan.getEstimatedEntryCount());
+ assertEquals((long) Math.ceil((double) numOfDocs / FulltextIndexPlanner.DEFAULT_NULL_CHECK_WEIGHT),
+ plan.getEstimatedEntryCount());
// Query on "foo" like x
filter = createFilter("nt:base");
diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPlannerCommonTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPlannerCommonTest.java
index 839523d23f..3fa7ed59f2 100644
--- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPlannerCommonTest.java
+++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexPlannerCommonTest.java
@@ -18,8 +18,12 @@
*/
package org.apache.jackrabbit.oak.plugins.index.lucene;
+import org.apache.jackrabbit.oak.InitialContent;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.plugins.index.IndexPlannerCommonTest;
+import org.apache.jackrabbit.oak.plugins.index.LuceneIndexOptions;
import org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReader;
import org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader;
import org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory;
@@ -30,14 +34,18 @@ import org.apache.jackrabbit.oak.plugins.index.search.IndexNode;
import org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner;
import org.apache.jackrabbit.oak.plugins.index.search.util.FunctionIndexProcessor;
import org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
import org.apache.jackrabbit.oak.plugins.memory.PropertyValues;
import org.apache.jackrabbit.oak.query.ast.Operator;
import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.mount.Mounts;
import org.apache.jackrabbit.oak.spi.query.Filter;
import org.apache.jackrabbit.oak.spi.query.QueryIndex;
import org.apache.jackrabbit.oak.spi.query.fulltext.FullTextParser;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.lucene.document.Document;
@@ -48,7 +56,6 @@ import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import java.io.IOException;
@@ -60,14 +67,16 @@ import java.util.Set;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.VERSION;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexStatistics.SYNTHETICALLY_FALLIABLE_FIELD;
import static org.apache.jackrabbit.oak.plugins.index.lucene.TestUtil.child;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition;
import static org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition;
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_FUNCTION;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
-import static org.junit.Assert.assertEquals;
public class LuceneIndexPlannerCommonTest extends IndexPlannerCommonTest {
+ {
+ indexOptions = new LuceneIndexOptions();
+ }
+
@Test
public void useNumDocsOnFieldForCost() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", Set.of("foo", "foo1", "foo2"), "async");
@@ -89,12 +98,13 @@ public class LuceneIndexPlannerCommonTest extends IndexPlannerCommonTest {
assertEquals(1.0, plan.getCostPerExecution(), 0);
assertEquals(1.0, plan.getCostPerEntry(), 0);
- // Query on "foo" is not null
+ // Query on "foo" is not null: no explicit weight -> heuristic weight applied
filter = createFilter("nt:base");
filter.restrictProperty("foo", Operator.NOT_EQUAL, null);
planner = new FulltextIndexPlanner(node, "/test", filter, Collections.emptyList());
plan = planner.getPlan();
- assertEquals(numOfDocs, plan.getEstimatedEntryCount());
+ assertEquals((long) Math.ceil((double) numOfDocs / FulltextIndexPlanner.DEFAULT_NULL_CHECK_WEIGHT),
+ plan.getEstimatedEntryCount());
// Query on "foo" like x
filter = createFilter("nt:base");
@@ -355,45 +365,40 @@ public class LuceneIndexPlannerCommonTest extends IndexPlannerCommonTest {
Directory sampleDirectory = createSampleDirectory(0, list);
LuceneIndexNode node = createIndexNode(idxDefn, sampleDirectory);
- // foo is null
- // that can be at most 20, because there are only
- // that many documents with ":nullProps"
+ // foo is null: no explicit weight -> heuristic weight=5 applied to :nullProps docCount (20) -> ceil(20/5) = 4
FilterImpl filter = createFilter("nt:unstructured");
filter.restrictProperty("foo", Operator.EQUAL, null);
FulltextIndexPlanner planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
- assertEquals(20, plan.getEstimatedEntryCount());
+ assertEquals(4, plan.getEstimatedEntryCount());
assertEquals(1.0, plan.getCostPerExecution(), 0);
assertEquals(1.0, plan.getCostPerEntry(), 0);
- // foo2 is null:
- // that can be at most 20, because there are only 10 documents with this property
+ // foo2 is null: same :nullProps docCount (20), heuristic weight=5 -> ceil(20/5) = 4
filter = createFilter("nt:unstructured");
filter.restrictProperty("foo2", Operator.EQUAL, null);
planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
plan = planner.getPlan();
- assertEquals(20, plan.getEstimatedEntryCount());
+ assertEquals(4, plan.getEstimatedEntryCount());
assertEquals(1.0, plan.getCostPerExecution(), 0);
assertEquals(1.0, plan.getCostPerEntry(), 0);
- // foo is not null:
- // that can be at most 10, because there are only 10 documents with this property
+ // foo is not null: no explicit weight -> heuristic weight=5 applied to foo docCount (10) -> ceil(10/5) = 2
filter = createFilter("nt:unstructured");
filter.restrictProperty("foo", Operator.NOT_EQUAL, null);
planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
plan = planner.getPlan();
- assertEquals(10, plan.getEstimatedEntryCount());
+ assertEquals(2, plan.getEstimatedEntryCount());
assertEquals(1.0, plan.getCostPerExecution(), 0);
assertEquals(1.0, plan.getCostPerEntry(), 0);
- // foo2 is not null:
- // that can be at most 0, because there are no documents wit this property
+ // foo2 is not null: foo2 docCount is 0, ceil(0/5) = 0
filter = createFilter("nt:unstructured");
filter.restrictProperty("foo2", Operator.NOT_EQUAL, null);
@@ -609,6 +614,26 @@ public class LuceneIndexPlannerCommonTest extends IndexPlannerCommonTest {
+ @Override
+ protected ContentRepository createContentRepository(MemoryNodeStore store) {
+ LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider();
+ LuceneIndexProvider indexProvider = new LuceneIndexProvider();
+ return new Oak(store)
+ .with(new InitialContent())
+ .with(new OpenSecurityProvider())
+ .with(editorProvider)
+ .with((Observer) indexProvider)
+ .with((QueryIndexProvider) indexProvider)
+ .createContentRepository();
+ }
+
+ @Override
+ protected IndexNode getIndexNodeFromStore(String indexPath, NodeState root) throws IOException {
+ IndexTracker tracker = new IndexTracker();
+ tracker.update(root);
+ return tracker.acquireIndexNode(indexPath);
+ }
+
@Override
protected IndexNode createIndexNode(IndexDefinition defn) throws IOException {
return new LuceneIndexNodeManager("foo", (LuceneIndexDefinition) defn, new TestReaderFactory(createSampleDirectory()).createReaders((LuceneIndexDefinition) defn, EMPTY_NODE, defn.getIndexPath()), null).acquire();
@@ -628,17 +653,6 @@ public class LuceneIndexPlannerCommonTest extends IndexPlannerCommonTest {
return new LuceneIndexDefinition(root, defn, indexPath);
}
- @Override
- protected NodeBuilder getPropertyIndexDefinitionNodeBuilder(@NotNull NodeBuilder builder, @NotNull String name, @NotNull Set<String> includes, @NotNull String async) {
- NodeBuilder oakIndex = builder.child("oak:index");
- return newLucenePropertyIndexDefinition(oakIndex, name, includes, async);
- }
-
- @Override
- protected NodeBuilder getIndexDefinitionNodeBuilder(@NotNull NodeBuilder index, @NotNull String name, @Nullable Set<String> propertyTypes) {
- return newLuceneIndexDefinition(index, name, propertyTypes);
- }
-
@Override
protected FulltextIndexPlanner getIndexPlanner(IndexNode indexNode, String indexPath, Filter filter, List<QueryIndex.OrderEntry> sortOrder) {
return new FulltextIndexPlanner(indexNode, indexPath, filter, sortOrder);
diff --git a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexProviderService.java b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexProviderService.java
index 0c6efc53f4..37d0697086 100644
--- a/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexProviderService.java
+++ b/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexProviderService.java
@@ -30,7 +30,9 @@ import org.apache.jackrabbit.oak.plugins.index.elastic.query.inference.Inference
import org.apache.jackrabbit.oak.plugins.index.elastic.query.inference.InferenceMBeanImpl;
import org.apache.jackrabbit.oak.plugins.index.fulltext.PreExtractedTextProvider;
import org.apache.jackrabbit.oak.plugins.index.search.ExtractedTextCache;
+import org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner;
import org.apache.jackrabbit.oak.query.QueryEngineSettings;
+import org.apache.jackrabbit.oak.spi.toggle.FeatureToggle;
import org.apache.jackrabbit.oak.spi.commit.Observer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -58,6 +60,8 @@ import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
+import static java.util.Collections.emptyMap;
+
import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay;
@@ -208,6 +212,9 @@ public class ElasticIndexProviderService {
metricHandler.markEnabled(isElasticAvailable);
whiteboard = new OsgiWhiteboard(bundleContext);
+ oakRegs.add(whiteboard.register(FeatureToggle.class,
+ new FeatureToggle(FulltextIndexPlanner.FT_OAK_12171, FulltextIndexPlanner.FT_OAK_12171_DISABLE),
+ emptyMap()));
if (System.getProperty(QueryEngineSettings.OAK_INFERENCE_ENABLED) != null) {
this.isInferenceEnabled = Boolean.parseBoolean(System.getProperty(QueryEngineSettings.OAK_INFERENCE_ENABLED));
} else {
diff --git a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexPlannerCommonTest.java b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexPlannerCommonTest.java
index 516148a5c5..e17f37199b 100644
--- a/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexPlannerCommonTest.java
+++ b/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexPlannerCommonTest.java
@@ -18,29 +18,33 @@
*/
package org.apache.jackrabbit.oak.plugins.index.elastic;
+import org.apache.jackrabbit.oak.InitialContent;
+import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.plugins.index.IndexPlannerCommonTest;
import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
import org.apache.jackrabbit.oak.plugins.index.TestUtil;
import org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.index.elastic.query.ElasticIndexPlanner;
+import org.apache.jackrabbit.oak.plugins.index.elastic.query.ElasticIndexProvider;
import org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder;
-import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.IndexNode;
import org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner;
import org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
import org.apache.jackrabbit.oak.query.index.FilterImpl;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
import org.apache.jackrabbit.oak.spi.query.Filter;
import org.apache.jackrabbit.oak.spi.query.QueryIndex;
import org.apache.jackrabbit.oak.spi.query.fulltext.FullTextParser;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -53,18 +57,11 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;
import static javax.jcr.PropertyType.TYPENAME_STRING;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
-import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
-import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
-import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
-import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -77,7 +74,7 @@ public class ElasticIndexPlannerCommonTest extends IndexPlannerCommonTest {
// before it can get the estimated doc count from the remote ES index
@Rule
public final ProvideSystemProperty updateSystemProperties
- = new ProvideSystemProperty("oak.elastic.statsRefreshSeconds", "5");
+ = new ProvideSystemProperty("oak.elastic.statsRefreshSeconds", "1");
@Rule
public final RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
@@ -157,6 +154,35 @@ public class ElasticIndexPlannerCommonTest extends IndexPlannerCommonTest {
}
+ @Override
+ protected ContentRepository createContentRepository(MemoryNodeStore store) {
+ ElasticIndexTracker tracker = new ElasticIndexTracker(esConnection, new ElasticMetricHandler(StatisticsProvider.NOOP));
+ ElasticIndexEditorProvider editorProvider = new ElasticIndexEditorProvider(tracker, esConnection, null);
+ return new Oak(store)
+ .with(new InitialContent())
+ .with(new OpenSecurityProvider())
+ .with(editorProvider)
+ .with(tracker)
+ .with(new ElasticIndexProvider(tracker))
+ .createContentRepository();
+ }
+
+ @Override
+ protected IndexNode getIndexNodeFromStore(String indexPath, NodeState root) {
+ return new ElasticIndexNodeManager(indexPath, root, esConnection).getIndexNode();
+ }
+
+ @Override
+ protected Map<String, Object> getCommitAttributes() {
+ return Map.of("sync-mode", "rt");
+ }
+
+ @Override
+ protected void awaitIndexing() {
+ // wait for ES stats to refresh (oak.elastic.statsRefreshSeconds=1 in test rule)
+ try { Thread.sleep(2000); } catch (InterruptedException ignored) {}
+ }
+
@Override
protected IndexNode createIndexNode(IndexDefinition defn) throws IOException {
try {
@@ -183,38 +209,6 @@ public class ElasticIndexPlannerCommonTest extends IndexPlannerCommonTest {
return new ElasticIndexDefinition(root, defn, indexPath, esConnection.getIndexPrefix());
}
- @Override
- protected NodeBuilder getPropertyIndexDefinitionNodeBuilder(@NotNull NodeBuilder builder, @NotNull String name, @NotNull Set<String> includes, @NotNull String async) {
- checkArgument(!includes.isEmpty(), "Lucene property index " +
- "requires explicit list of property names to be indexed");
- NodeBuilder defBuilder = builder.child("oak:index");
- defBuilder = defBuilder.child(name);
- defBuilder.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
- .setProperty(TYPE_PROPERTY_NAME, indexOptions.getIndexType())
- .setProperty(REINDEX_PROPERTY_NAME, true);
- defBuilder.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
- defBuilder.setProperty(createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_NAMES, includes, STRINGS));
-
- return defBuilder;
- }
-
- @Override
- protected NodeBuilder getIndexDefinitionNodeBuilder(@NotNull NodeBuilder index, @NotNull String name, @Nullable Set<String> propertyTypes) {
- if (index.hasChildNode(name)) {
- return index.child(name);
- }
- NodeBuilder indexDefBuilder = index.child(name);
- indexDefBuilder.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
- .setProperty(TYPE_PROPERTY_NAME, indexOptions.getIndexType())
- .setProperty(REINDEX_PROPERTY_NAME, true);
-
- if (propertyTypes != null && !propertyTypes.isEmpty()) {
- indexDefBuilder.setProperty(createProperty(FulltextIndexConstants.INCLUDE_PROPERTY_TYPES,
- propertyTypes, STRINGS));
- }
- return indexDefBuilder;
- }
-
@Override
protected FulltextIndexPlanner getIndexPlanner(IndexNode indexNode, String indexPath, Filter filter, List<QueryIndex.OrderEntry> sortOrder) {
return new ElasticIndexPlanner(indexNode, indexPath, filter, sortOrder);
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/FulltextIndexConstants.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/FulltextIndexConstants.java
index aa29ddad5d..04b870e430 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/FulltextIndexConstants.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/FulltextIndexConstants.java
@@ -139,6 +139,18 @@ public interface FulltextIndexConstants {
String PROP_WEIGHT = "weight";
+ /**
+ * Weight used for cost estimation of "is null" property restrictions.
+ * Falls back to {@link #PROP_WEIGHT} if not set.
+ */
+ String PROP_WEIGHT_NULL = "weightNull";
+
+ /**
+ * Weight used for cost estimation of "is not null" property restrictions.
+ * Falls back to {@link #PROP_WEIGHT} if not set.
+ */
+ String PROP_WEIGHT_NOT_NULL = "weightNotNull";
+
String PROP_DYNAMIC_BOOST = "dynamicBoost";
float DYNAMIC_BOOST_WEIGHT = 0.0001f;
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/PropertyDefinition.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/PropertyDefinition.java
index 90001b9ac9..4078f91410 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/PropertyDefinition.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/PropertyDefinition.java
@@ -106,6 +106,24 @@ public class PropertyDefinition {
public final int weight;
+ /**
+ * Whether the {@code weight} property was explicitly set in the index definition.
+ * Used to distinguish an explicitly configured weight from the default value.
+ */
+ public final boolean hasExplicitWeight;
+
+ /**
+ * Weight for cost estimation of "is null" restrictions.
+ * -1 if not explicitly configured; falls back to {@link #weight}.
+ */
+ public final int weightNull;
+
+ /**
+ * Weight for cost estimation of "is not null" restrictions.
+ * -1 if not explicitly configured; falls back to {@link #weight}.
+ */
+ public final int weightNotNull;
+
public final boolean dynamicBoost;
/**
@@ -143,7 +161,10 @@ public class PropertyDefinition {
this.name = getNamePropertyValue(defn, nodeName);
this.relative = isRelativeProperty(name);
this.boost = getOptionalValue(defn, FIELD_BOOST, DEFAULT_BOOST);
+ this.hasExplicitWeight = defn.hasProperty(PROP_WEIGHT);
this.weight = getOptionalValue(defn, PROP_WEIGHT, DEFAULT_PROPERTY_WEIGHT);
+ this.weightNull = getOptionalValue(defn, FulltextIndexConstants.PROP_WEIGHT_NULL, -1);
+ this.weightNotNull = getOptionalValue(defn, FulltextIndexConstants.PROP_WEIGHT_NOT_NULL, -1);
this.dynamicBoost = getOptionalValue(defn, FulltextIndexConstants.PROP_DYNAMIC_BOOST, false);
//By default if a property is defined it is indexed
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
index 9fffe4c866..5bd413085a 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
@@ -72,6 +72,27 @@ public class FulltextIndexPlanner {
public static final int DEFAULT_PROPERTY_WEIGHT = Integer.getInteger("oak.fulltext.defaultPropertyWeight", 5);
+ /**
+ * Default weight used for null/not-null cost estimation when no explicit weight is configured.
+ * Corresponds to the heuristic that such conditions match ~20% of indexed entries.
+ */
+ public static final int DEFAULT_NULL_CHECK_WEIGHT = 5;
+
+ /**
+ * Feature toggle name for OAK-12171.
+ * When the toggle is enabled (set to true), the improved null/not-null weight estimation
+ * is disabled and the legacy behavior (weight=1) is used instead.
+ * The improved behavior is active by default.
+ */
+ public static final String FT_OAK_12171 = "FT_OAK-12171";
+
+ /**
+ * Kill switch for the improved null/not-null weight estimation introduced by OAK-12171.
+ * Set to {@code true} to revert to the legacy behavior. Default is {@code false} (improved
+ * behavior active). This is wired to the {@link #FT_OAK_12171} feature toggle at runtime.
+ */
+ public static final AtomicBoolean FT_OAK_12171_DISABLE = new AtomicBoolean(false);
+
/**
* IndexPlan Attribute name which refers to the name of the fields that should be used for facets.
*/
@@ -814,6 +835,21 @@ public class FulltextIndexPlanner {
return PathUtils.denotesRoot(parentPath) ? "" : parentPath;
}
+ /**
+ * Returns the effective weight to use for null/not-null cost estimation.
+ * Priority: specificWeight (weightNull/weightNotNull) > propertyWeight (if explicitly
+ * configured and > 1) > {@link #DEFAULT_NULL_CHECK_WEIGHT} heuristic.
+ */
+ private static int resolveNullCheckWeight(int specificWeight, int propertyWeight, boolean hasExplicitWeight) {
+ if (specificWeight > 0) {
+ return specificWeight;
+ }
+ if (hasExplicitWeight && propertyWeight > 1) {
+ return propertyWeight;
+ }
+ return DEFAULT_NULL_CHECK_WEIGHT;
+ }
+
private int getNumDocs() {
IndexStatistics indexStatistics = indexNode.getIndexStatistics();
if (indexStatistics == null) {
@@ -850,13 +886,19 @@ public class FulltextIndexPlanner {
if (pr != null) {
if (pr.isNotNullRestriction()) {
- // don't use weight for "is not null" restrictions
- // as all documents with this field can match;
- weight = 1;
+ if (FT_OAK_12171_DISABLE.get()) {
+ weight = 1;
+ } else {
+ PropertyDefinition pd = propDef.getValue();
+ weight = resolveNullCheckWeight(pd.weightNotNull, pd.weight, pd.hasExplicitWeight);
+ }
} else if (pr.isNullRestriction()) {
- // don't use the weight for "is null" restrictions
- // as all documents with ":nullProps" can match
- weight = 1;
+ if (FT_OAK_12171_DISABLE.get()) {
+ weight = 1;
+ } else {
+ PropertyDefinition pd = propDef.getValue();
+ weight = resolveNullCheckWeight(pd.weightNull, pd.weight, pd.hasExplicitWeight);
+ }
} else {
if (weight > 1) {
// for non-equality conditions such as
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/util/IndexDefinitionBuilder.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/util/IndexDefinitionBuilder.java
index a1db37d648..64268aba1a 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/util/IndexDefinitionBuilder.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/util/IndexDefinitionBuilder.java
@@ -477,6 +477,16 @@ public class IndexDefinitionBuilder {
return this;
}
+ public PropertyRule weightNull(int weight) {
+ propTree.setProperty(FulltextIndexConstants.PROP_WEIGHT_NULL, weight);
+ return this;
+ }
+
+ public PropertyRule weightNotNull(int weight) {
+ propTree.setProperty(FulltextIndexConstants.PROP_WEIGHT_NOT_NULL, weight);
+ return this;
+ }
+
public PropertyRule boost(float boost) {
propTree.setProperty(FIELD_BOOST, (double) boost, Type.DOUBLE);
return this;
diff --git a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexPlannerCommonTest.java b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexPlannerCommonTest.java
index 881610482f..3790da1fef 100644
--- a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexPlannerCommonTest.java
+++ b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexPlannerCommonTest.java
@@ -19,8 +19,15 @@
package org.apache.jackrabbit.oak.plugins.index;
import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.index.search.PropertyDefinition;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.apache.jackrabbit.oak.plugins.index.search.FieldNames;
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.IndexNode;
@@ -53,15 +60,24 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static javax.jcr.PropertyType.TYPENAME_STRING;
import static java.util.Objects.requireNonNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.oak.InitialContentHelper.INITIAL_CONTENT;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.FULL_TEXT_ENABLED;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_NAMES;
+import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.INCLUDE_PROPERTY_TYPES;
import static org.apache.jackrabbit.oak.plugins.index.TestUtil.child;
import static org.apache.jackrabbit.oak.plugins.index.TestUtil.registerTestNodeType;
import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.EVALUATE_PATH_RESTRICTION;
@@ -73,7 +89,6 @@ import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProp
import static org.apache.jackrabbit.oak.spi.query.QueryConstants.REP_FACET;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -1529,12 +1544,32 @@ public abstract class IndexPlannerCommonTest {
protected abstract IndexDefinition getIndexDefinition(NodeState root, NodeState defn, String indexPath);
- protected abstract NodeBuilder getPropertyIndexDefinitionNodeBuilder(@NotNull NodeBuilder builder, @NotNull String name,
- @NotNull Set<String> includes,
- @NotNull String async);
-
- protected abstract NodeBuilder getIndexDefinitionNodeBuilder(@NotNull NodeBuilder index, @NotNull String name,
- @Nullable Set<String> propertyTypes);
+ protected NodeBuilder getPropertyIndexDefinitionNodeBuilder(@NotNull NodeBuilder builder, @NotNull String name,
+ @NotNull Set<String> includes,
+ @NotNull String async) {
+ NodeBuilder defBuilder = builder.child(INDEX_DEFINITIONS_NAME).child(name);
+ defBuilder.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
+ .setProperty(TYPE_PROPERTY_NAME, indexOptions.getIndexType())
+ .setProperty(REINDEX_PROPERTY_NAME, true);
+ defBuilder.setProperty(FULL_TEXT_ENABLED, false);
+ defBuilder.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, includes, STRINGS));
+ return defBuilder;
+ }
+
+ protected NodeBuilder getIndexDefinitionNodeBuilder(@NotNull NodeBuilder index, @NotNull String name,
+ @Nullable Set<String> propertyTypes) {
+ if (index.hasChildNode(name)) {
+ return index.child(name);
+ }
+ NodeBuilder defBuilder = index.child(name);
+ defBuilder.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
+ .setProperty(TYPE_PROPERTY_NAME, indexOptions.getIndexType())
+ .setProperty(REINDEX_PROPERTY_NAME, true);
+ if (propertyTypes != null && !propertyTypes.isEmpty()) {
+ defBuilder.setProperty(createProperty(INCLUDE_PROPERTY_TYPES, propertyTypes, STRINGS));
+ }
+ return defBuilder;
+ }
protected abstract FulltextIndexPlanner getIndexPlanner(IndexNode indexNode,
String indexPath,
@@ -1544,5 +1579,159 @@ public abstract class IndexPlannerCommonTest {
protected abstract IndexDefinitionBuilder getIndexDefinitionBuilder(NodeBuilder builder);
+ protected abstract ContentRepository createContentRepository(MemoryNodeStore store) throws IOException;
+
+ protected abstract IndexNode getIndexNodeFromStore(String indexPath, NodeState root) throws IOException;
+
+ protected Map<String, Object> getCommitAttributes() {
+ return Collections.emptyMap();
+ }
+
+ protected void awaitIndexing() {
+ // no-op by default; backends with eventual consistency (e.g. Elastic) override this
+ }
+
+ /**
+ * Creates an index node where {@code notNullCount} documents have the given property
+ * and {@code nullCount} documents are recorded as missing it.
+ */
+ protected final IndexNode createIndexNodeForNullCheckTest(IndexDefinition defn, String propertyName,
+ int notNullCount, int nullCount) throws IOException {
+ MemoryNodeStore store = new MemoryNodeStore();
+ ContentRepository repo = createContentRepository(store);
+ try (ContentSession session = repo.login(null, null)) {
+ Root jcrRoot = session.getLatestRoot();
+ String idxName = PathUtils.getName(defn.getIndexPath());
+ IndexDefinitionBuilder idxBuilder = getIndexDefinitionBuilder();
+ idxBuilder.noAsync();
+ idxBuilder.includedPaths("/content-" + idxName);
+ IndexDefinition.IndexingRule rule = defn.getApplicableIndexingRule("nt:unstructured");
+ if (rule != null) {
+ PropertyDefinition pd = rule.getConfig(propertyName);
+ if (pd != null) {
+ IndexDefinitionBuilder.PropertyRule propRule = idxBuilder.indexRule("nt:unstructured")
+ .property(propertyName).propertyIndex();
+ if (pd.nullCheckEnabled) propRule.nullCheckEnabled();
+ if (pd.notNullCheckEnabled) propRule.notNullCheckEnabled();
+ if (pd.hasExplicitWeight) propRule.weight(pd.weight);
+ if (pd.weightNull > 0) propRule.weightNull(pd.weightNull);
+ if (pd.weightNotNull > 0) propRule.weightNotNull(pd.weightNotNull);
+ }
+ }
+ Tree oakIndex = jcrRoot.getTree("/").addChild(INDEX_DEFINITIONS_NAME);
+ idxBuilder.build(oakIndex.addChild(idxName));
+ jcrRoot.commit();
+ Tree content = jcrRoot.getTree("/").addChild("content-" + idxName);
+ for (int i = 0; i < notNullCount; i++) {
+ Tree n = content.addChild("nn" + i);
+ n.setProperty(JCR_PRIMARYTYPE, "nt:unstructured", NAME);
+ n.setProperty(propertyName, "v" + i);
+ }
+ for (int i = 0; i < nullCount; i++) {
+ content.addChild("nl" + i).setProperty(JCR_PRIMARYTYPE, "nt:unstructured", NAME);
+ }
+ jcrRoot.commit(getCommitAttributes());
+ } catch (Exception e) {
+ throw new IOException("Failed to create index node for null check test", e);
+ }
+ awaitIndexing();
+ return getIndexNodeFromStore(defn.getIndexPath(), store.getRoot());
+ }
+
+ protected void assertEquals(long expected, long got) {
+ org.junit.Assert.assertEquals(expected, got);
+ }
+
+ protected void assertEquals(double expected, double actual, double delta) {
+ org.junit.Assert.assertEquals(expected, actual, delta);
+ }
+
+ protected void assertEquals(Object expected, Object actual) {
+ org.junit.Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void nullCheckWeightEstimation() throws Exception {
+ String indexPath = "/" + INDEX_DEFINITIONS_NAME + "/test";
+ IndexDefinitionBuilder idxBuilder = getIndexDefinitionBuilder(child(builder, indexPath));
+ idxBuilder.indexRule("nt:unstructured")
+ .property("updated").propertyIndex().nullCheckEnabled().notNullCheckEnabled().weight(500);
+ IndexDefinition idxDefn = getIndexDefinition(root, idxBuilder.build(), indexPath);
+ IndexNode node = createIndexNodeForNullCheckTest(idxDefn, "updated", 100, 200);
+
+ // "is null" with weight=500 as fallback: ceil(200/500) = 1
+ FilterImpl filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.EQUAL, null);
+ FulltextIndexPlanner planner = getIndexPlanner(node, indexPath, filter, Collections.emptyList());
+ assertEquals(1, planner.getPlan().getEstimatedEntryCount());
+
+ // "is not null" with weight=500 as fallback: ceil(100/500) = 1
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.NOT_EQUAL, null);
+ planner = getIndexPlanner(node, indexPath, filter, Collections.emptyList());
+ assertEquals(1, planner.getPlan().getEstimatedEntryCount());
+
+ // explicit weightNull=10 overrides weight: ceil(200/10) = 20
+ String indexPath2 = "/" + INDEX_DEFINITIONS_NAME + "/test2";
+ idxBuilder = getIndexDefinitionBuilder(child(builder, indexPath2));
+ idxBuilder.indexRule("nt:unstructured")
+ .property("updated").propertyIndex().nullCheckEnabled().weight(500).weightNull(10);
+ IndexNode node2 = createIndexNodeForNullCheckTest(
+ getIndexDefinition(root, idxBuilder.build(), indexPath2), "updated", 100, 200);
+
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.EQUAL, null);
+ planner = getIndexPlanner(node2, indexPath2, filter, Collections.emptyList());
+ assertEquals(20, planner.getPlan().getEstimatedEntryCount());
+
+ // explicit weightNotNull=5 overrides weight: ceil(100/5) = 20
+ String indexPath3 = "/" + INDEX_DEFINITIONS_NAME + "/test3";
+ idxBuilder = getIndexDefinitionBuilder(child(builder, indexPath3));
+ idxBuilder.indexRule("nt:unstructured")
+ .property("updated").propertyIndex().notNullCheckEnabled().weight(500).weightNotNull(5);
+ IndexNode node3 = createIndexNodeForNullCheckTest(
+ getIndexDefinition(root, idxBuilder.build(), indexPath3), "updated", 100, 200);
+
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.NOT_EQUAL, null);
+ planner = getIndexPlanner(node3, indexPath3, filter, Collections.emptyList());
+ assertEquals(20, planner.getPlan().getEstimatedEntryCount());
+
+ // no explicit weight -> DEFAULT_NULL_CHECK_WEIGHT applied
+ String indexPath4 = "/" + INDEX_DEFINITIONS_NAME + "/test4";
+ idxBuilder = getIndexDefinitionBuilder(child(builder, indexPath4));
+ idxBuilder.indexRule("nt:unstructured")
+ .property("updated").propertyIndex().nullCheckEnabled().notNullCheckEnabled();
+ IndexNode node4 = createIndexNodeForNullCheckTest(
+ getIndexDefinition(root, idxBuilder.build(), indexPath4), "updated", 100, 200);
+
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.EQUAL, null);
+ planner = getIndexPlanner(node4, indexPath4, filter, Collections.emptyList());
+ assertEquals((long) Math.ceil(200.0 / FulltextIndexPlanner.DEFAULT_NULL_CHECK_WEIGHT),
+ planner.getPlan().getEstimatedEntryCount());
+
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.NOT_EQUAL, null);
+ planner = getIndexPlanner(node4, indexPath4, filter, Collections.emptyList());
+ assertEquals((long) Math.ceil(100.0 / FulltextIndexPlanner.DEFAULT_NULL_CHECK_WEIGHT),
+ planner.getPlan().getEstimatedEntryCount());
+
+ // kill switch: FT_OAK-12171 enabled -> old behavior (weight=1, raw docCount returned)
+ FulltextIndexPlanner.FT_OAK_12171_DISABLE.set(true);
+ try {
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.EQUAL, null);
+ planner = getIndexPlanner(node, indexPath, filter, Collections.emptyList());
+ assertEquals(200, planner.getPlan().getEstimatedEntryCount());
+
+ filter = createFilter("nt:unstructured");
+ filter.restrictProperty("updated", Operator.NOT_EQUAL, null);
+ planner = getIndexPlanner(node, indexPath, filter, Collections.emptyList());
+ assertEquals(100, planner.getPlan().getEstimatedEntryCount());
+ } finally {
+ FulltextIndexPlanner.FT_OAK_12171_DISABLE.set(false);
+ }
+ }
}