feat: support CreateIndex
and IndexType::Normal
& IndexType::Composite
#154
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.
What problem does this PR solve?
feat:
CreateIndex
andIndexType::Normal
&IndexType::Composite
IndexType::Composite
range detachuse
RangeDetacher
sequentially obtain the relevant columns in the composite index, and only when the previous one is of equal value can I detach the next column.Case 1: There is an index with three columns
a, b, c
. WhenWHERE a = 1 AND b > 1
, the range of a=1 and b >1 can be extracted. The index can use the composite index ofa, b, c
. (ifWHERE a > 1 AND b = 1
then the index cannot be used)Case 2: There are two indexes with one column
a
and three columnsa, b, c
. WhenWHERE (a = 1 AND b > 1) OR a > 1
, the range of aAND
b cannot be extracted, but at this time the range of a range can be extracted and isa >= 1
, so you can use a single-column index with columna
Tips: Case 2 can use similar
index merging
to perform better queries, but this may be optimized later.ref:
Index Selection
create table and index
TODO
When the case is
select * from t1 where (c1 = 7 or c1 = 10) and c2 < 2;
, the range is (-inf, (10, 2)), in fact it is better to be ((7), (7) ,2)), ((10), (10, 2))Code changes
Check List
Tests
Side effects
Note for reviewer