Skip to content

OAK-12057 - Select same plan with or without LIMIT option#2722

Merged
thomasmueller merged 2 commits intoapache:OAK-12057from
bhabegger:bugfix/fix-union-with-limit
Feb 4, 2026
Merged

OAK-12057 - Select same plan with or without LIMIT option#2722
thomasmueller merged 2 commits intoapache:OAK-12057from
bhabegger:bugfix/fix-union-with-limit

Conversation

@bhabegger
Copy link
Contributor

No description provided.

Comment on lines -1120 to -1125
if (sortOrder == null || p.getSortOrder() != null) {
// if the query is unordered, or
// if the query contains "order by" and the index can sort on that,
// then we don't need to read all entries from the index
entryCount = Math.min(maxEntryCount, entryCount);
}
Copy link
Contributor Author

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

@bhabegger bhabegger force-pushed the bugfix/fix-union-with-limit branch 2 times, most recently from f7907ec to 6e5104a Compare February 3, 2026 16:10
String query = "SELECT * FROM [rep:Authorizable] WHERE [rep:principalName] = 'anonymous'";
session.getLatestRoot().getQueryEngine().executeQuery(query, JCR_SQL2, 1, 0, null, null);

boolean evaluationContinueLogPresent = false;
Copy link
Contributor Author

@bhabegger bhabegger Feb 3, 2026

Choose a reason for hiding this comment

The 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)

@bhabegger bhabegger force-pushed the bugfix/fix-union-with-limit branch from 6e5104a to 0dec652 Compare February 3, 2026 18:02
QueryIndex index = queryIndexes.get(i);
double minCost = index.getMinimumCost();
if (minCost > bestCost) {
if (Math.abs(minCost - bestIndex.getMinimumCost()) < .00001) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerning the broken test.

I've try to look into this a bit deeper. In the original case, as there was a limit of 1 so the best cost of test-index1 up around the minimal cost of test-index3 with the latter still bigger than the former but then passing through this if.

Currently, dropping the limit all indices are evaluated as their minCost is definitely below the bestCost.

So, I wondering, is the scenario that lead to this situation still valid ? If so, what case would that be and how to simulate it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check. Maybe the test needs to be changed.

@bhabegger bhabegger force-pushed the bugfix/fix-union-with-limit branch from 0dec652 to e1108ed Compare February 4, 2026 12:18
@thomasmueller thomasmueller marked this pull request as ready for review February 4, 2026 12:36
@thomasmueller
Copy link
Member

Merging it, but only into the branch

@thomasmueller thomasmueller merged commit 3f7e4cd into apache:OAK-12057 Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants