Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2134

AggregateJoinTransposeRule fails in optimize phase based on CBO because of the bug in RelMdColumnUniqueness

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      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.

      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)
      

      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.

        
      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;
        }
      

      Attachments

        1. 02.sql
          0.8 kB
          Jing Zhang
        2. 02-snippet.sql
          0.2 kB
          Jing Zhang

        Activity

          People

            Unassigned Unassigned
            jingzhang Jing Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: