[
https://issues.apache.org/jira/browse/CALCITE-1876?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16078365#comment-16078365
]
Julian Hyde commented on CALCITE-1876:
--------------------------------------
I see two options:
# A rule, called say AggregateProjectableTableScanRule, that matches an
Aggregate on top of a TableScan for a ProjectableFilterableTable, and pushes
the implicit projects into the table
# A rule, called say AggregateInduceProjectRule, that converts an Aggregate
into an Aggregate on top of a Project.
The second of these, AggregateInduceProjectRule, is more powerful. It can
handle intermediate relational expressions, for example {{select max(name) from
Emp where deptno = 10}} it would create a Project that could be pushed through
the Filter and then into the TableScan. The first could not do this.
But we'd have to be careful that AggregateInduceProjectRule didn't fire too
often. It should not fire if an Aggregate uses all of its input fields (this
would be a sign that the Aggregate had been created by the rule). Also note
that it is the converse of
[AggregateProjectMergeRule|https://insight.io/github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/rules/AggregateProjectMergeRule.java],
so obviously those rules need to be kept a safe distance from each other.
> Create a rule to push the projections used in aggregate functions
> -----------------------------------------------------------------
>
> Key: CALCITE-1876
> URL: https://issues.apache.org/jira/browse/CALCITE-1876
> Project: Calcite
> Issue Type: Improvement
> Components: csv-adapter
> Reporter: Luis Fernando Kauer
> Assignee: Julian Hyde
> Priority: Minor
>
> From Julian Hyde;
> "Calcite should realize that Aggregate has an implied Project (because it
> only uses a few columns) and push that projection into the CsvTableScan, but
> it doesn’t."
> A query scans only the used projection when no aggregation is used:
> sql->explain plan for select name from emps;
> CsvTableScan(table=[[SALES, EMPS]], fields=[[1]])
> But it scans all the projections when an aggregation is used:
> sql->explain plan for select max(name) from emps;
> EnumerableAggregate(group=[{}], EXPR$0=[MAX($1)])
> CsvTableScan(table=[[SALES, EMPS]], fields=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)