[ 
https://issues.apache.org/jira/browse/CALCITE-4011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17112438#comment-17112438
 ] 

Haisheng Yuan commented on CALCITE-4011:
----------------------------------------

Thanks for taking this, [~amaliujia]!
If top-down optimization is enabled, any enforcer (including sort, shuffle) 
should not be created explicitly by any rule or relnode, only 
Convention.enforce() has the privilege to create enforcer operator, and it is 
called by planner. Sort related rules in calcite will be useless, because they 
generate many junk alternatives.
During trait propagation, each physical operator just needs to do:
1. If it is required some traits by parent operator, what trait can it deliver 
and require its child operator to deliver.
2. If its child can deliver some trait, what trait can it derive from this 
child, and require other children to deliver corresponding traits.

For Project, e.g.

{code:java}
select a, b, cnt+2 as c from
  (select a, b, count(*) cnt from foo group by a,b) t
order by b desc, a desc; -- case 1
-- order by b desc; -- case 2
{code}

The initial logical plan before passing to VolcanoPlanner may look like:

{code:java}
LogicalSort
      -> LogicalProject
                   -> LogicalAggregate
                                -> LogicalTableScan
{code}
After implementation, it may look like:
{code:java}
           EnumerableProject
                   -> EnumerableSortedAggregate
                                -> EnumerableTableScan
{code}
The root relset has a desired traitset with collation on b desc, a desc.
The project is required by parent (here is the root) with collation [b desc, a 
desc].
It can pass the required traits down to child operator, it will return what 
traits if will require its child to satisfy, and at the same itself's new 
traitset after pass required traitset. 
If this process is done, with SortProjectTransposeRule disabled, we should 
still be able to see the following plan  (for both queries):

{code:java}
           EnumerableProject
                   -> EnumerableSortedAggregate
                                -> EnumerableSort
                                             -> EnumerableTableScan
{code:java}


> Implement trait propagation for EnumerableProject and EnumerableFilter
> ----------------------------------------------------------------------
>
>                 Key: CALCITE-4011
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4011
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Haisheng Yuan
>            Assignee: Rui Wang
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> So that parent trait can be passed down, and it can derive new traitsets from 
> child. Most importantly, as a demonstration. So that SortProjectTransposeRule 
> and ProjectSortTransposeRule can be disabled when topDownOpt is enabled.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to