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

Add post-aggregation step for Union in materialized view rewriting

    Details

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

      Description

      Follow-up on CALCITE-1795.

      Rewriting for Aggregate queries needs a post-aggregation step that is not currently added.

      Query:

      SELECT empid, deptname, SUM(salary) AS s
      FROM emps
      JOIN depts ON (emps.deptno = depts.deptno)
      WHERE salary > 10000
      GROUP BY empid, deptname;
      

      Materialized view definition:

      SELECT empid, deptname, SUM(salary) AS s
      FROM emps
      JOIN depts ON (emps.deptno = depts.deptno)
      WHERE salary > 12000
      GROUP BY empid, deptname;
      

      Rewriting:

      SELECT empid, deptname, SUM(s)
      FROM (
      SELECT empid, deptname, s
      FROM mv
      UNION ALL
      SELECT empid, deptname, SUM(salary) AS s
      FROM emps
      JOIN depts ON (emps.deptno = depts.deptno)
      WHERE salary > 10000 AND salary <= 12000
      GROUP BY empid, deptname) subq
      GROUP BY empid, deptname;
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jcamachorodriguez Jesus Camacho Rodriguez
                Reporter:
                jcamachorodriguez Jesus Camacho Rodriguez
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: