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

RelBuilder.aggregate should prune unused fields from the input, if the input is a Project

    XMLWordPrintableJSON

Details

    Description

      RelBuilder.aggregate should prune unused fields from the input, if the input is a Project.

      Pruning fields during the planning process is desirable, but often cannot do it - we are applying a RelOptRule that has to return the same fields, or we don't want to add an extra Project do so the pruning. But when we are in RelBuilder.aggregate and the input is a Project, neither of those limitations apply. We already have a Project, we are just making it narrower; and we know what fields the Aggregate will produce.

      For example,

      SELECT deptno, SUM(sal) FILTER (WHERE b)
      FROM (
        SELECT deptno, empno + 10, sal, job = 'CLERK' AS b
        FROM emp)
      GROUP BY deptno
      

      becomes

      SELECT deptno, SUM(sal) FILTER (WHERE b)
      FROM (
        SELECT deptno, sal, job = 'CLERK' AS b
        FROM emp)
      GROUP BY deptno
      

      If there are no fields used, remove the Project. (A RelNode with no fields is not allowed.)

      SELECT COUNT(*) AS C
      FROM (
       SELECT deptno, empno + 10, sal, job = 'CLERK' AS b
       FROM emp)
      

      becomes

      SELECT COUNT(*) AS c
      FROM emp
      

      Add an option RelBuilder.Config.pruneInputOfAggregate, default true, so that people can disable this rewrite if it causes problems.

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h