-
Notifications
You must be signed in to change notification settings - Fork 90
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
IGNITE-19615: Index is not used while performing SELECT over an indexed column. #2196
Conversation
408027e
to
d6e5f4f
Compare
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.
After this patch an index is used indeed. But resulting plan is rather invalid. For a query like SELECT val FROM my WHERE id = 100500
, where id
is of type TINYINT, I've got following plan:
IgniteExchange<...>
IgniteIndexScan(<...>, searchBounds=[[ExactBounds [bound=CAST(100500):TINYINT NOT NULL]]], filters=[=(CAST($t0):INTEGER NOT NULL, 100500)]<...>
this results in RuntimeException, since 100500 is out of range of TINYINT
@korlov42 |
Optimiser starts from:
And produces:
|
Yep. Types are correct.
So the problem should be in SearchBound assembly code. |
9ad11fe
to
baadc49
Compare
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.
First problem with this patch is that now IgniteTypeCoercion has two similar method with different behaviour:
boolean needToCast(RelDataType fromType, RelDataType toType)
boolean needToCast(SqlValidatorScope scope, SqlNode node, RelDataType toType)
The former returns false
for (TINYINT, INTEGER), while the latter returns true
in the very similar case (node::TINYINT, INTEGER).
The second problem is that it deals with literals only, while leaving dynamic params and columns references out of scope for some reason
d5c2cd9
to
20f7db9
Compare
What makes you think so? Search bounds can be built from arbitrary expressions, if it was not the case then the optimizer wouldn't be able to select an index for |
6524587
to
f9b7b91
Compare
e3a2944
to
1806534
Compare
That would not work. Left all as it is - just renamed a method to |
…ed column. Remove TypeUtils::needCast.
…ed column. updated comment.
…ed column. Add test cases.
…ed column. Move to Utils.
…ed column. Move to Utils.
…ed column. Comments.
# Conflicts: # modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSecondaryIndexTest.java
…ed column. Add comments.
…ed column. Add comments.
|
* Checks whether one type can be casted to another if one of type is a custom data type. | ||
* This method expects at least one of its arguments to be a custom data type. |
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.
* Checks whether one type can be casted to another if one of type is a custom data type. | |
* This method expects at least one of its arguments to be a custom data type. | |
* Checks whether one type can be casted to another if one of type is a custom data type. | |
* | |
* <p>This method expects at least one of its arguments to be a custom data type. |
* This method expects at least one of its arguments to be a custom data type. | ||
*/ | ||
public static boolean customDataTypeNeedCast(IgniteTypeFactory factory, RelDataType fromType, RelDataType toType) { | ||
assert fromType.getSqlTypeName() == SqlTypeName.ANY || toType.getSqlTypeName() == SqlTypeName.ANY : |
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.
why do we need both this assertion and one on line 584? Let's leave only one on line 584 with improved message
…ed column. fix assertion error.
/** Checks whether cast operation is necessary in {@code SearchBound}. */ | ||
public static boolean needCastInSearchBounds(IgniteTypeFactory typeFactory, RelDataType fromType, RelDataType toType) { | ||
// Check custom data types first. | ||
if (toType.getSqlTypeName() == SqlTypeName.ANY || fromType.getSqlTypeName() == SqlTypeName.ANY) { |
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.
this predicate doesn't seem right... Method customDataTypeNeedCast
actually expects that at least one of the argument is instance of IgniteCustomType. If there is an invariant that there should not be any ANY type but IgniteCustomType, it's better to check it explicitly
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.
@korlov42 yeap. I removed the first assertion since the second one is the only one that is needed.
public static boolean needCastInSearchBounds(IgniteTypeFactory typeFactory, RelDataType fromType, RelDataType toType) { | ||
// Check custom data types first. | ||
if (toType.getSqlTypeName() == SqlTypeName.ANY || fromType.getSqlTypeName() == SqlTypeName.ANY) { | ||
return customDataTypeNeedCast(typeFactory, fromType, toType); |
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.
why do even need call in needCastInSearchBounds? This is the very same rule as in TypeCoercion
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.
Fixed.
…ed column. Cleanup.
…ed column. Cleanup.
Removed int type / interval type checks from TypeCoercion::needToCast(Type, Type) - it behaves exactly the same way as TypeUtils::needToCast (which was removed in https://issues.apache.org/jira/browse/IGNITE-19128).