Vladsz83 commented on code in PR #10390:
URL: https://github.com/apache/ignite/pull/10390#discussion_r1043343200
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/IndexCountRule.java:
##########
@@ -54,18 +57,50 @@ private IndexCountRule(IndexCountRule.Config cfg) {
LogicalAggregate aggr = call.rel(0);
IgniteLogicalTableScan scan = call.rel(1);
IgniteTable table = scan.getTable().unwrap(IgniteTable.class);
- IgniteIndex idx = table.getIndex(QueryUtils.PRIMARY_KEY_INDEX);
if (
- idx == null ||
- table.isIndexRebuildInProgress() ||
- scan.condition() != null ||
- aggr.getGroupCount() > 0 ||
- aggr.getAggCallList().stream().anyMatch(a ->
a.getAggregation().getKind() != SqlKind.COUNT ||
- !a.getArgList().isEmpty() || a.hasFilter())
+ table.isIndexRebuildInProgress() ||
+ scan.condition() != null ||
+ aggr.getGroupCount() > 0 ||
+ aggr.getAggCallList().size() != 1
)
return;
+ AggregateCall agg = aggr.getAggCallList().get(0);
+
+ if (agg.getAggregation().getKind() != SqlKind.COUNT || agg.hasFilter()
|| agg.isDistinct())
+ return;
+
+ List<Integer> argList = agg.getArgList();
+
+ IgniteIndex idx = null;
+ boolean notNull = false;
+
+ if (argList.isEmpty())
+ idx = table.getIndex(QueryUtils.PRIMARY_KEY_INDEX);
+ else {
+ if (scan.projects() != null || argList.size() > 1)
+ return;
+
+ notNull = true;
+ int fieldIdx = argList.get(0);
+
+ if (!scan.requiredColumns().isEmpty())
+ fieldIdx = scan.requiredColumns().nth(fieldIdx);
+
+ for (IgniteIndex idx0 : table.indexes().values()) {
+ List<RelFieldCollation> fieldCollations =
idx0.collation().getFieldCollations();
+
+ if (!fieldCollations.isEmpty() &&
fieldCollations.get(0).getFieldIndex() == fieldIdx) {
Review Comment:
The rule's javadoc says:
/** Tries to optimize 'COUNT(*)' to use number of index records. */
Might be changed to smth like
/** Tries to optimize 'COUNT()' to use number of index records. */
Non only all (*)
--
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]