-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improving search by compound indexes. #3915
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2b14525
Improving search by compound indexes.
kiss034 48b72bf
Fixing review findings.
kiss034 c57a62f
Fixing the index condition handling.
kiss034 1e4c3e8
Adjusting test cases.
kiss034 0dbfc32
Fixing TableFilter.prepare().
kiss034 1b9cb56
Adjusting test cases.
kiss034 5b80dd9
Refactoring the constructors of the IndexCondition class.
kiss034 e7b8be5
Removing unnecessary TODOs.
kiss034 89363a2
Fixing review findings.
kiss034 a8ba33a
Introducing the TestCompoundIndexSearch class.
kiss034 705d965
Preparing IndexCondition to deal with queries where the columns not u…
kiss034 76f34d0
Fixing test errors.
kiss034 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 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
package org.h2.expression.condition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
import org.h2.engine.SessionLocal; | ||
|
@@ -139,12 +140,37 @@ public void createIndexConditions(SessionLocal session, TableFilter filter) { | |
} else if (left instanceof ExpressionList) { | ||
ExpressionList list = (ExpressionList) left; | ||
if (!list.isArray()) { | ||
createIndexConditions(filter, list); | ||
// First we create a compound index condition. | ||
createCompoundIndexCondition(filter); | ||
// If there is no compound index, then the TableFilter#prepare() method will drop this condition. | ||
// Then we create a unique index condition for each column. | ||
createUniqueIndexConditions(filter, list); | ||
// If there are two or more index conditions, IndexCursor will only use the first one. | ||
// See: IndexCursor#canUseIndexForIn(Column) | ||
} | ||
} | ||
} | ||
|
||
private void createIndexConditions(TableFilter filter, ExpressionList list) { | ||
/** | ||
* Creates a compound index condition containing every item in the expression list. | ||
* @see IndexCondition#getCompoundInList(ExpressionList, List) | ||
*/ | ||
private void createCompoundIndexCondition(TableFilter filter) { | ||
// We do not check filter here, because the IN condition can contain columns from multiple tables. | ||
ExpressionVisitor visitor = ExpressionVisitor.getNotFromResolverVisitor(filter); | ||
for (Expression e : valueList) { | ||
if (!e.isEverything(visitor)) { | ||
return; | ||
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. {} 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. Done |
||
} | ||
} | ||
filter.addIndexCondition(IndexCondition.getCompoundInList((ExpressionList) left, valueList)); | ||
} | ||
|
||
/** | ||
* Creates a unique index condition for every item in the expression list. | ||
* @see IndexCondition#getInList(ExpressionColumn, List) | ||
*/ | ||
private void createUniqueIndexConditions(TableFilter filter, ExpressionList list) { | ||
int c = list.getSubexpressionCount(); | ||
for (int i = 0; i < c; i++) { | ||
Expression e = list.getSubexpression(i); | ||
|
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.
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.
Done