-
Notifications
You must be signed in to change notification settings - Fork 426
OAK-12057 - Select same plan with or without LIMIT option #2722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomasmueller
merged 2 commits into
apache:OAK-12057
from
bhabegger:bugfix/fix-union-with-limit
Feb 4, 2026
+127
−86
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,8 @@ | |
| package org.apache.jackrabbit.oak; | ||
|
|
||
| import ch.qos.logback.classic.Level; | ||
| import org.apache.jackrabbit.api.JackrabbitRepository; | ||
| import org.apache.jackrabbit.api.JackrabbitSession; | ||
| import org.apache.jackrabbit.oak.api.ContentRepository; | ||
| import org.apache.jackrabbit.oak.api.ContentSession; | ||
| import org.apache.jackrabbit.oak.commons.junit.LogCustomizer; | ||
| import org.apache.jackrabbit.oak.jcr.Jcr; | ||
| import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexPlan; | ||
|
|
@@ -28,6 +28,7 @@ | |
| import org.apache.jackrabbit.oak.spi.query.Filter; | ||
| import org.apache.jackrabbit.oak.spi.query.QueryIndex; | ||
| import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider; | ||
| import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider; | ||
| import org.apache.jackrabbit.oak.spi.state.NodeState; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.junit.After; | ||
|
|
@@ -36,66 +37,61 @@ | |
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
|
|
||
| import javax.jcr.Node; | ||
| import javax.jcr.Repository; | ||
| import javax.jcr.SimpleCredentials; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static javax.jcr.query.Query.JCR_SQL2; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class IndexCostEvaluationTest { | ||
| @Rule | ||
| public TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target")); | ||
|
|
||
| private static final String TEST_USER_NAME = "testUserName"; | ||
|
|
||
| private Repository repository = null; | ||
| private JackrabbitSession session = null; | ||
| private Node root = null; | ||
| private LogCustomizer custom; | ||
| private ContentSession session = null; | ||
| private LogCustomizer logCollector; | ||
|
|
||
| @Before | ||
| public void before() throws Exception { | ||
| custom = LogCustomizer | ||
| logCollector = LogCustomizer | ||
| .forLogger( | ||
| "org.apache.jackrabbit.oak.query.QueryImpl") | ||
| .enable(Level.DEBUG).create(); | ||
| custom.starting(); | ||
|
|
||
|
|
||
| TestIndexProvider testProvider = new TestIndexProvider(); | ||
| TestIndexProvider2 testProvider2 = new TestIndexProvider2(); | ||
| TestIndexProvider3 testProvider3 = new TestIndexProvider3(); | ||
|
|
||
| Jcr jcr = new Jcr() | ||
| .with((QueryIndexProvider) testProvider) | ||
| .with((QueryIndexProvider) testProvider2) | ||
| .with((QueryIndexProvider) testProvider3); | ||
|
|
||
| repository = jcr.createRepository(); | ||
| session = (JackrabbitSession) repository.login(new SimpleCredentials("admin", "admin".toCharArray())); | ||
| root = session.getRootNode(); | ||
| logCollector.starting(); | ||
| double luceneMinCost = 2.2; | ||
| double elasticMinCost = 2.1; | ||
| TestIndexProvider testProvider = new TestIndexProvider("test-index", luceneMinCost); | ||
| TestIndexProvider testProvider2 = new TestIndexProvider("test-index2", luceneMinCost); | ||
| TestIndexProvider testProvider3 = new TestIndexProvider("test-index3", elasticMinCost); | ||
|
|
||
| Jcr jcr = new Jcr(new Oak(), false) | ||
| .with(new OpenSecurityProvider()) | ||
| .with(new InitialContent()) | ||
| .with(testProvider) | ||
| .with(testProvider2) | ||
| .with(testProvider3); | ||
|
|
||
| ContentRepository repository = jcr.createContentRepository(); | ||
| session = repository.login(null, null); | ||
| } | ||
|
|
||
|
|
||
| @After | ||
| public void after() { | ||
| custom.finished(); | ||
| session.logout(); | ||
| if (repository instanceof JackrabbitRepository) { | ||
| ((JackrabbitRepository) repository).shutdown(); | ||
| } | ||
| public void after() throws IOException { | ||
| session.close(); | ||
| logCollector.finished(); | ||
| } | ||
|
|
||
| // In cases where two indexes have same min cost i.e. both indexes are on par, we don't skip cost evaluation | ||
| // even of cost from previous index is less than min cost of new index. | ||
| @Test | ||
| public void costEvaluationTest() throws Exception { | ||
| String query = "SELECT * FROM [rep:Authorizable] WHERE [rep:principalName] = 'anonymous'"; | ||
| session.getLatestRoot().getQueryEngine().executeQuery(query, JCR_SQL2, 1, 0, null, null); | ||
|
|
||
| boolean evaluationContinueLogPresent = false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simplified the test a bit to reduce it to one explicit query rather than 3 implicit with one of them generating the expected log entries. (It's in a separate commit so that we can check that it passed before, and that now it no longer passes) |
||
| boolean evaluationSkipLogPresent = false; | ||
| for (String log : custom.getLogs()) { | ||
| for (String log : logCollector.getLogs()) { | ||
| if (log.equals("minCost: 2.1 of index :test-index2 > best Cost: 2.0 from index: test-index, but both indexes have same minimum cost - cost evaluation will continue")) { | ||
| evaluationContinueLogPresent = true; | ||
| } | ||
|
|
@@ -107,44 +103,32 @@ public void costEvaluationTest() throws Exception { | |
| assertTrue(evaluationSkipLogPresent); | ||
| } | ||
|
|
||
| private class TestIndexProvider implements QueryIndexProvider { | ||
| TestIndex index = new TestIndex(); | ||
| private static class TestIndexProvider implements QueryIndexProvider { | ||
| private final TestIndex index; | ||
|
|
||
| public TestIndexProvider(String indexName, double minimumCost) { | ||
| this.index = new TestIndex(indexName, minimumCost); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull List<? extends QueryIndex> getQueryIndexes(NodeState nodeState) { | ||
| return List.of(index); | ||
| } | ||
| } | ||
|
|
||
| private class TestIndexProvider2 extends TestIndexProvider { | ||
| public TestIndexProvider2() { | ||
| this.index = new TestIndex() { | ||
| public String getIndexName() { | ||
| return "test-index2"; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| private static class TestIndex implements QueryIndex, QueryIndex.AdvancedQueryIndex { | ||
|
|
||
| private class TestIndexProvider3 extends TestIndexProvider { | ||
| public TestIndexProvider3() { | ||
| this.index = new TestIndex() { | ||
| public String getIndexName() { | ||
| return "test-index3"; | ||
| } | ||
|
|
||
| public double getMinimumCost() { | ||
| return PropertyIndexPlan.COST_OVERHEAD + 0.11; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| private final String name; | ||
| private final double minimumCost; | ||
|
|
||
| private class TestIndex implements QueryIndex, QueryIndex.AdvancedQueryIndex { | ||
| public TestIndex(String indexName, double minimumCost) { | ||
| this.name = indexName; | ||
| this.minimumCost = minimumCost; | ||
| } | ||
|
|
||
| @Override | ||
| public double getMinimumCost() { | ||
| return PropertyIndexPlan.COST_OVERHEAD + 0.1; | ||
| return minimumCost; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -164,15 +148,15 @@ public String getPlan(Filter filter, NodeState rootState) { | |
|
|
||
| @Override | ||
| public String getIndexName() { | ||
| return "test-index"; | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) { | ||
| IndexPlan.Builder b = new IndexPlan.Builder(); | ||
| Filter f = new FilterImpl(null, "SELECT * FROM [nt:file]", new QueryEngineSettings()); | ||
| IndexPlan plan1 = b.setEstimatedEntryCount(10).setPlanName("testIndexPlan1").setFilter(f).build(); | ||
| List<IndexPlan> indexList = new ArrayList<IndexPlan>(); | ||
| List<IndexPlan> indexList = new ArrayList<>(); | ||
|
|
||
| indexList.add(plan1); | ||
| return indexList; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomasmueller This is the part that leads to the change in costs of the broken test