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

Materialized view rewriting may swap columns in equivalent classes incorrectly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.17.0
    • Fix Version/s: 1.18.0
    • Component/s: core
    • Labels:
      None

      Description

      https://github.com/apache/calcite/blob/323200507b72fec152e2f557b3f7f2209a042fe4/core/src/main/java/org/apache/calcite/rel/rules/AbstractMaterializedViewRule.java#L2542

            Set<RexTableInputRef> c1 = nodeToEquivalenceClass.get(p1);
            Set<RexTableInputRef> c2 = nodeToEquivalenceClass.get(p2);
            if (c1 != null && c2 != null) {
              // Both present, we need to merge
              if (c1.size() < c2.size()) {
                // We swap them to merge
                c1 = c2; // <-- HERE.  Should c1 and c2 be actually swapped?
                p1 = p2; // <-- What does this mean? p1 and p2 are not used. Should they be swapped as well just in case
              }
              for (RexTableInputRef newRef : c2) {
                c1.add(newRef);
                nodeToEquivalenceClass.put(newRef, c1);
              }
      

      It looks like c1 vs c2 swap is missing, and a mere c1=c2 is used.
      It would likely produce weird results.

      /cc Jesus Camacho Rodriguez

        Attachments

          Activity

            People

            • Assignee:
              jcamachorodriguez Jesus Camacho Rodriguez
              Reporter:
              vladimirsitnikov Vladimir Sitnikov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: