liyafan82 commented on a change in pull request #2355:
URL: https://github.com/apache/calcite/pull/2355#discussion_r589917976
##########
File path:
core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
##########
@@ -227,6 +227,21 @@ public Double getDistinctRowCount(Values rel,
RelMetadataQuery mq,
return 1D;
}
}
+
+ // try to remove const columns from the group keys, as they do not
+ // affect the distinct row count
+ ImmutableBitSet nonConstCols = rel.getNonConstColumns(groupKey);
+ if (nonConstCols.cardinality() == 0) {
+ // all columns are constants, the distinct row count should be 1
+ return 1D;
+ }
+
+ if (nonConstCols.cardinality() < groupKey.cardinality()) {
+ // some const columns can be removed, call the method recursively
+ // with the trimmed columns
+ return getDistinctRowCount(rel, mq, nonConstCols, predicate);
+ }
Review comment:
It would return the of distinct row count from the input, which is null
for most cases.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]