[ 
https://issues.apache.org/jira/browse/CALCITE-3711?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17008681#comment-17008681
 ] 

Ruben Q L commented on CALCITE-3711:
------------------------------------

I think we could provide a simple implementation such as:
{code:java}
public abstract class Correlate extends BiRel {
  ...
  @Override public double estimateRowCount(RelMetadataQuery mq) {
    return mq.getRowCount(left) * mq.getRowCount(right);
  }
{code}
which is very basic, but still better than the current default implementation 
(1.0).
 [~vladimirsitnikov], I can create a PR with this small change; or maybe we 
could consider including this change as part of your big 
[PR#1702|https://github.com/apache/calcite/pull/1702], which involves cost 
computation and impacts already Correlate.java. What do you think?

> Correlate should override estimateRowCount
> ------------------------------------------
>
>                 Key: CALCITE-3711
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3711
>             Project: Calcite
>          Issue Type: Improvement
>    Affects Versions: 1.21.0
>            Reporter: Ruben Q L
>            Priority: Major
>
> Currently, Correlate inherits the {{estimateRowCount}} implementation from 
> AbstractRelNode:
> {code:java}
> public double estimateRowCount(RelMetadataQuery mq) {
>   return 1.0;
> }
> {code}
> which gives a "default" (but unrealistic) row count computation.
> This has several issues:
> - This value may be used by {{Correlate#computeSelfCost}} (and by inheritance 
> by LogicalCorrelate / EnumerableCorrelate):
> {code:java}
> @Override public RelOptCost computeSelfCost(final RelOptPlanner planner, 
> final RelMetadataQuery mq) {
>   double rowCount = mq.getRowCount(this);  // by default: estimateRowCount, 
> i.e. 1.0
>   ...
> {code}
> - As the current state, this value will definitely by used by several join 
> algorithms in their cost computation if their left/right child is a Correlate:
> {code:java}
> public class EnumerableHashJoin extends Join implements EnumerableRel {
> ...
>   @Override public RelOptCost computeSelfCost(RelOptPlanner planner, 
> RelMetadataQuery mq) {
>     ...
>     final double rightRowCount = right.estimateRowCount(mq); // 1.0 if right 
> is a Correlate
>     final double leftRowCount = left.estimateRowCount(mq); // 1.0 if left is 
> a Correlate
>     ... 
> {code}
> Even though cost computation is pluggable (which would help solving issues 
> like the first one, but not issues like the second one), IMHO we should 
> provide a more realistic default {{Correlate#estimateRowCount}} computation.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to