alex-plekhanov commented on a change in pull request #9671:
URL: https://github.com/apache/ignite/pull/9671#discussion_r803359215
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/LogicalRelImplementor.java
##########
@@ -298,13 +301,106 @@ 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 && !tbl.isIndexRebuildInProgress()) {
+ 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.
+ // If there are correlates in filter or project, spool node is
required to provide ability to rewind input.
+ // Sort node is required if output should be sorted or if spool
node required (to provide search by
+ // index conditions).
+ // Additionally, project node is required in case of spool
inserted, since spool requires unmodified
+ // original input for filtering by index conditions.
+ boolean filterHasCorrelation = condition != null &&
RexUtils.hasCorrelation(condition);
+ boolean projectHasCorrelation = projects != null &&
RexUtils.hasCorrelation(projects);
+ boolean spoolNodeRequired = projectHasCorrelation ||
filterHasCorrelation;
+ boolean projNodeRequired = projects != null && spoolNodeRequired;
+
+ 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);
+ RelCollation collation = rel.collation();
+
+ if ((!spoolNodeRequired && projects != null) || requiredColumns !=
null) {
+ collation =
collation.apply(LogicalScanConverterRule.createMapping(
+ spoolNodeRequired ? null : projects,
+ requiredColumns,
+ tbl.getRowType(typeFactory).getFieldCount()
+ ));
+ }
+
+ boolean sortNodeRequired =
!collation.getFieldCollations().isEmpty();
+
+ if (sortNodeRequired) {
+ if (!spoolNodeRequired && projects != null)
+ rowType = rel.getRowType();
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]