You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "jingzhang (JIRA)" <ji...@apache.org> on 2018/01/13 05:43:00 UTC

[jira] [Created] (CALCITE-2134) AggregateJoinTransposeRule fails in optimize phase based on CBO because of the bug in RelMdColumnUniqueness

jingzhang created CALCITE-2134:
----------------------------------

             Summary: AggregateJoinTransposeRule fails in optimize phase based on CBO because of the bug in RelMdColumnUniqueness
                 Key: CALCITE-2134
                 URL: https://issues.apache.org/jira/browse/CALCITE-2134
             Project: Calcite
          Issue Type: Bug
            Reporter: jingzhang
            Assignee: Julian Hyde
         Attachments: 02-snippet.sql, 02.sql

If runs tpch 02 query(in attachment) or snippet of 02(in attachment), the following exception will be thrown in AggregateJoinTranspose Rule during optimized phase based on VolcanoPlanner.
{code}
java.lang.AssertionError
	at org.apache.calcite.sql.SqlSplittableAggFunction$SelfSplitter.topSplit(SqlSplittableAggFunction.java:209)
	at org.apache.calcite.rel.rules.AggregateJoinTransposeRule.onMatch(AggregateJoinTransposeRule.java:310)
	at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:212)
	at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:650)
{code}
The failure is caused by the RelMdColumnUniqueness's estimation of RelSubset type RelNodes, which does not take Join into consideration. I don't figure out why only includes Aggregate, Filter, Values, TableScan, Project yet.
{code}  
public Boolean areColumnsUnique(RelSubset rel, RelMetadataQuery mq,
      ImmutableBitSet columns, boolean ignoreNulls) {
    int nullCount = 0;
    for (RelNode rel2 : rel.getRels()) {
      if (rel2 instanceof Aggregate
          || rel2 instanceof Filter
          || rel2 instanceof Values
          || rel2 instanceof TableScan
          || simplyProjects(rel2, columns)) {
        try {
          final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls);
          if (unique != null) {
            if (unique) {
              return true;
            }
          } else {
            ++nullCount;
          }
        } catch (CyclicMetadataException e) {
          // Ignore this relational expression; there will be non-cyclic ones
          // in this set.
        }
      }
    }
    return nullCount == 0 ? false : null;
  }
{code}




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)