-
Notifications
You must be signed in to change notification settings - Fork 424
OAK-12057 Wrong index may be selected when using LIMIT OPTION #2724
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3f7e4cd
OAK-12057 - Select same plan with or without LIMIT option (#2722)
bhabegger e8a9d63
OAK-12057 - Select same plan with or without LIMIT option (update tes…
thomasmueller 1814954
OAK-12057: Add feature toggle for LIMIT-aware index selection (#2831)
bhabegger 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
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
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
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
Oops, something went wrong.
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.
@bhabegger , I think we should not just clear this condition. Take following example:
Lets say we have a query with sort, but only one index support the sorted filter other don't. So the cost estimation now will be based on index size but in fact index which support sort may be better.
The addition of limit brings all indexes at same level because limit is used to get MaxEntry count, may be what we need is to bring in index's entry count to picture when finalising best best index.
long entryCount = p.getEstimatedEntryCount();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.
The issue with limit is that the same index will not be chose with or without the limit which in certain cases is surprising.
This said, I completely understand that taking a sorting capable index over one which doesn't support it. So here the challenge is that we have cases which favor one and cases which favor the other. But maybe, couldn't we always favor indices which support sorting systematically rather than only if their is a limit ?
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.
IMO yes, sorting is something that need complete result set before we can return results. If we already have index solving sorting, it saves all the jcr calls we will have to make to all data and then sorting it in memory.
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.
Most relational databases account for this by adding a "cost to sort". In our case, the indexes return the same cost (which is fine), and report whether they can sort or not. So the query engines task is to add a "cost to sort" (on top of the cost returned by the indexes) for indexes that can not sort. This almost exactly matches the description "favor indices which support sorting systematically" but not 100%. What it means that an index that can not sort can still be cheaper in total than index that can sort. It just depends on the cost of sorting in the query engine.
(In Jackrabbit Oak, the Lucene and Elastic indexes often report wildly inaccurate numbers (orders of magnitude wrong), because we do not have accurate statistics currently. So such improvements will likely not have a big impact currently.)
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.
Maybe we should split the discussion:
For this PR I see the following options:
If we go for the last, what should we add ? What would be the formula ?
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.
I think we agree we don't want to add more to the PR... Yes it's not perfect, but perfection is the enemy of the good...
On the other hand, if we don't have an agreement on whether this PR might be risky or not, I think we could introduce a feature toggle. @tihom88 WDYT?
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.
I think we can go ahead with this approach. The limit checks were also added quite recently.
But we should add cost for sorting logic in a separate jira.