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

Add post-aggregation step for Union in materialized view rewriting

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.13.0
    • core
    • 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

              jcamacho Jesús Camacho Rodríguez
              jcamacho Jesús Camacho Rodríguez
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: