databend
                                
                                 databend copied to clipboard
                                
                                    databend copied to clipboard
                            
                            
                            
                        Feature: optimize common table expression(CTE)
Summary
Need RFC.
Currently, databend processes CTE by inlining all references to CTEs in the query tree.
This causes the CTE to execute multiple, but further optimization can be done with CTE in the context of the plan tree(such as join pushdown)
So we should leverage CBO to decide when to inline or not inline CTE.
There is a paper as reference: http://www.vldb.org/pvldb/vol8/p1704-elhelw.pdf