korlov42 commented on a change in pull request #9671:
URL: https://github.com/apache/ignite/pull/9671#discussion_r789042877
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/LogicalRelImplementor.java
##########
@@ -298,13 +301,101 @@ public LogicalRelImplementor(
Supplier<Row> upper = upperCond == null ? null :
expressionFactory.rowSource(upperCond);
Function<Row, Row> prj = projects == null ? null :
expressionFactory.project(projects, rowType);
+ ColocationGroup grp = ctx.group(rel.sourceId());
+
IgniteIndex idx = tbl.getIndex(rel.indexName());
- ColocationGroup group = ctx.group(rel.sourceId());
+ if (idx != null) {
+ Iterable<Row> rowsIter = idx.scan(ctx, grp, filters, lower, upper,
prj, requiredColumns);
+
+ return new ScanNode<>(ctx, rowType, rowsIter);
+ }
+ else {
+ // Index was invalidated after planning, workaround through
table-scan -> sort -> index spool.
+ RelCollation collation = TraitUtils.collation(rel);
+
+ boolean filterHasCorrelation = condition != null &&
RexUtils.hasCorrelation(condition);
+ boolean projectHasCorrelation = projects != null &&
RexUtils.hasCorrelation(projects);
+ boolean spoolNodeRequired = projectHasCorrelation ||
filterHasCorrelation;
+ boolean projNodeRequired = projects != null && spoolNodeRequired;
+ boolean hasCollation = collation != null &&
!collation.getFieldCollations().isEmpty();
+
+ Iterable<Row> rowsIter = tbl.scan(
+ ctx,
+ grp,
+ filterHasCorrelation ? null : filters,
+ projNodeRequired ? null : prj,
+ requiredColumns
+ );
- Iterable<Row> rowsIter = idx.scan(ctx, group, filters, lower, upper,
prj, requiredColumns);
+ Node<Row> node = new ScanNode<>(ctx, rowType, rowsIter);
- return new ScanNode<>(ctx, rowType, rowsIter);
+ if (hasCollation || spoolNodeRequired) {
Review comment:
Why do we create a SortNode for an empty collation?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]