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;
      

        Issue Links

          Activity

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/c8462e1 .
          Hide
          jcamachorodriguez Jesus Camacho Rodriguez added a comment -

          Added fix to bail out if aggregation is on DISTINCT and additional tests in http://git-wip-us.apache.org/repos/asf/calcite/commit/83cef58.

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Added fix to bail out if aggregation is on DISTINCT and additional tests in http://git-wip-us.apache.org/repos/asf/calcite/commit/83cef58 .
          Hide
          jcamachorodriguez Jesus Camacho Rodriguez added a comment -

          Resolved in release 1.13.0 (2017-06-26).

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.13.0 (2017-06-26).

            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:

                Development