You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "lowka (via GitHub)" <gi...@apache.org> on 2023/06/15 06:49:04 UTC
[GitHub] [ignite-3] lowka opened a new pull request, #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
lowka opened a new pull request, #2196:
URL: https://github.com/apache/ignite-3/pull/2196
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).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247659288
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
+ return customDataTypeNeedCast(typeFactory, fromType, toType);
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1604448948
Optimiser starts from:
> LogicalProject(VAL=[$1]), id = 116
> LogicalFilter(condition=[=(CAST($0):INTEGER NOT NULL, 100500)]), id = 114
> IgniteLogicalTableScan(table=[[PUBLIC, MY]]), id = 113
And produces:
> IgniteExchange(distribution=[single]), id = 144
> IgniteTableScan(table=[[PUBLIC, MY]], filters=[=(CAST($t0):INTEGER NOT NULL, 100500)], projects=[[$t1]], requiredColumns=[{0, 1}]), id = 143
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1611162176
>The second problem is that it deals with literals only, while leaving dynamic params and columns references out of scope for some reason
What makes you think so? Search bounds are built from arbitrary expression, optimizer wouldn't be able to select an index.
But nonetheless I have reverted the changes to the state as were copied from ignite2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247547914
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
+ return customDataTypeNeedCast(typeFactory, fromType, toType);
+ }
+
+ // No need to cast between char and varchar.
+ if (SqlTypeUtil.isCharacter(toType) && SqlTypeUtil.isCharacter(fromType)) {
+ return false;
+ }
+
+ // No need to cast if the source type precedence list
+ // contains target type. i.e. do not cast from
+ // tinyint to int or int to bigint.
+ if (fromType.getPrecedenceList().containsType(toType)
+ && SqlTypeUtil.isIntType(fromType)
+ && SqlTypeUtil.isIntType(toType)) {
+ return false;
+ }
+
+ // Implicit type coercion does not handle nullability.
+ if (SqlTypeUtil.equalSansNullability(typeFactory, fromType, toType)) {
+ return false;
+ }
+ // Should keep sync with rules in SqlTypeCoercionRule.
+ assert SqlTypeUtil.canCastFrom(toType, fromType, true);
+ return true;
+ }
+
+ /**
+ * 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.
+ */
+ public static boolean customDataTypeNeedCast(IgniteTypeFactory factory, RelDataType fromType, RelDataType toType) {
+ assert fromType.getSqlTypeName() == SqlTypeName.ANY || toType.getSqlTypeName() == SqlTypeName.ANY :
Review Comment:
why do we need both this assertion and one on line 584? Let's leave only one on line 584 with improved message
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247560089
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
+ return customDataTypeNeedCast(typeFactory, fromType, toType);
Review Comment:
why do even need call in needCastInSearchBounds? This is the very same rule as in TypeCoercion
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1604399991
> 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
I going to look into it. I looked at the result of `IgniteSqlValidator` and it add `INTEGER` casts to both id and literal (this is expected). But somehow the bounds are still use `TINYINT`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247555482
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
Review Comment:
@korlov42 yeap. I removed the first assertion since the second one is the only one that is needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1613217462
* Partially reverted changes, that were made in https://issues.apache.org/jira/browse/IGNITE-19128 and moved type cast checks to TypeUtils.
* Added test cases with indexes to ImplicitCastsTest.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247553130
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
Review Comment:
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 merged pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 merged PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1611269431
>I have reverted the changes to the state as were copied from ignite2.
That would not work. Left all as it is - just renamed a method to `needToCastInIndex`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] korlov42 commented on a diff in pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "korlov42 (via GitHub)" <gi...@apache.org>.
korlov42 commented on code in PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#discussion_r1247545689
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/TypeUtils.java:
##########
@@ -533,6 +535,55 @@ public static NativeType columnType2NativeType(ColumnType columnType, int precis
}
}
+ /** 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) {
+ return customDataTypeNeedCast(typeFactory, fromType, toType);
+ }
+
+ // No need to cast between char and varchar.
+ if (SqlTypeUtil.isCharacter(toType) && SqlTypeUtil.isCharacter(fromType)) {
+ return false;
+ }
+
+ // No need to cast if the source type precedence list
+ // contains target type. i.e. do not cast from
+ // tinyint to int or int to bigint.
+ if (fromType.getPrecedenceList().containsType(toType)
+ && SqlTypeUtil.isIntType(fromType)
+ && SqlTypeUtil.isIntType(toType)) {
+ return false;
+ }
+
+ // Implicit type coercion does not handle nullability.
+ if (SqlTypeUtil.equalSansNullability(typeFactory, fromType, toType)) {
+ return false;
+ }
+ // Should keep sync with rules in SqlTypeCoercionRule.
+ assert SqlTypeUtil.canCastFrom(toType, fromType, true);
+ return true;
+ }
+
+ /**
+ * 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.
Review Comment:
```suggestion
* 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] lowka commented on pull request #2196: IGNITE-19615: Index is not used while performing SELECT over an indexed column.
Posted by "lowka (via GitHub)" <gi...@apache.org>.
lowka commented on PR #2196:
URL: https://github.com/apache/ignite-3/pull/2196#issuecomment-1604466190
Yep. Types are correct.
> SqlValidator BINARY_COMPARISON: CAST(`MY`.`ID` AS INTEGER) = 100500 types: INTEGER INTEGER
So the problem should be in SearchBound assembly code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org