[CALCITE-6650] Optimize the IN sub-query and SOME sub-query by Metada…#4022
Conversation
| // FALSE. | ||
| final RelMetadataQuery mq = e.rel.getCluster().getMetadataQuery(); | ||
| final Double maxRowCount = mq.getMaxRowCount(e.rel); | ||
| if (maxRowCount != null && maxRowCount < 1D) { |
There was a problem hiding this comment.
Are you sure that maxRowCount < 1D guarantees that the subquery will return zero records?
Since maxRowCount is a Double, I think if maxRowCount = 0.7 for example, there is a possibility that it could return more than 0 records.
There was a problem hiding this comment.
I have the same concern as @dssysolyatin. Could we instead check whether it is an instance of Values and then call Values.isEmpty? (Which is how PruneEmptyRules work.)
There was a problem hiding this comment.
We have rule in PruneEmptyRules that does:
return maxRowCount != null && maxRowCount == 0.0;Given that comparisons with doubles are inherently imprecise we may need to revisit that rule as well. Should we employ a threshold comparison?
There was a problem hiding this comment.
In addition, it seems that we employ the maxRowCount < 1D check in other places as well so whatever we decide we may need to propagate the changes everywhere.
There was a problem hiding this comment.
The semantics of this value should be documented. Is it always guaranteed to be less than the actual row count of the table?
There was a problem hiding this comment.
@zabetak Perhaps we should clarify more clearly that when 'maxRowCount==0D' means no data is returned?
There was a problem hiding this comment.
Sure. If you can find a better place to put the logic at
then do it. Maybe a method@Nullable Boolean RelMetadataQuery.isEmpty(RelNode) (where true means always empty, false means always non-empty, null for everything else).
I cannot imagine a case where a provider would return a maxRowCount value less than one where the relation was not guaranteed empty, so I wouldn't worry too much whether the condition is < 1D or == 0D.
There was a problem hiding this comment.
I think add @Nullable Boolean RelMetadataQuery.isEmpty(RelNode) is a good way for users to customize their implementation. The Default behavior will use maxRowCount == 0.0.
There was a problem hiding this comment.
Note that we don't allow people to override methods in RelMetadataQuery. If we want people to be able to customize we should create a new kind of metadata.
There was a problem hiding this comment.
I have created an issue CALCITE-6665 to log it.
mihaibudiu
left a comment
There was a problem hiding this comment.
This looks fine to me. Unless there are objections in the next few days I plan to merge this.
|
Feel free to squash the commits and merge if there are no other suggestions. |
|



…ta RowCount