[ https://issues.apache.org/jira/browse/CALCITE-5069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17515929#comment-17515929 ]
Xurenhe edited comment on CALCITE-5069 at 4/1/22 4:22 PM: ---------------------------------------------------------- I have pondered over the problem again and again. {code:java} // current code // RelMdRowCount#getRowCount(Minus, RelMetadataQuery) public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) { Double rowCount = null; for (RelNode input : rel.getInputs()) { Double partialRowCount = mq.getRowCount(input); if (rowCount == null || partialRowCount != null && partialRowCount < rowCount) { rowCount = partialRowCount; } } return rowCount; } {code} I'm confused about this formula. We shouldn't use the smallest input's count to estimate the count of Minus. eg: *a except b* if count of b is 0, this formula will return 0 I think the row-count of Minus may depend on the first's input. I agree with [~julianhyde] , re-open this issue Although in the safe mode, current formula may be wrong. By the way, it's too hard to define what's safe.:( was (Author: wojustme): I have pondered over the problem again and again. {code:java} // current code // RelMdRowCount#getRowCount(Minus, RelMetadataQuery) public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) { Double rowCount = null; for (RelNode input : rel.getInputs()) { Double partialRowCount = mq.getRowCount(input); if (rowCount == null || partialRowCount != null && partialRowCount < rowCount) { rowCount = partialRowCount; } } return rowCount; } {code} I'm confused about this formula. We shouldn't use the smallest input's count to estimate the count of Minus. eg: *a except b* if count of b is 0, this formula will return 0 I think the row-count of Minus may depend on the first's input. I agree with [~julianhyde] , re-open this issue Although in the safe mode, current formula may be wrong > Method of minus's getRowCount has not consider 'except all' > ----------------------------------------------------------- > > Key: CALCITE-5069 > URL: https://issues.apache.org/jira/browse/CALCITE-5069 > Project: Calcite > Issue Type: Improvement > Components: core > Reporter: Xurenhe > Assignee: Xurenhe > Priority: Major > > Current code of *RelMdRowCount* has not consider 'except all', it should be > double. > It's similar to > [CALCITE-3287|https://issues.apache.org/jira/browse/CALCITE-3287] and > [CALCITE-3988|https://issues.apache.org/jira/browse/CALCITE-3988] > CODE: *RelMdRowCount#getRowCount(Minus, RelMetadataQuery)* > > {code:java} > // now > public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) { > Double rowCount = null; > for (RelNode input : rel.getInputs()) { > Double partialRowCount = mq.getRowCount(input); > if (rowCount == null > || partialRowCount != null && partialRowCount < rowCount) { > rowCount = partialRowCount; > } > } > return rowCount; > } > // right > public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) { > Double rowCount = null; > for (RelNode input : rel.getInputs()) { > Double partialRowCount = mq.getRowCount(input); > if (rowCount == null > || partialRowCount != null && partialRowCount < rowCount) { > rowCount = partialRowCount; > } > } > if (rowCount == null || !rel.all) { > return rowCount; > } else { > return rowCount * 2; > } > }{code} > > -- This message was sent by Atlassian Jira (v8.20.1#820001)