seawinde opened a new pull request, #55066:
URL: https://github.com/apache/doris/pull/55066

   ### What problem does this PR solve?
   
   Support window function rewrite when materialized view contains window 
function
   
   Such as mv def is as following:
   ```sql
           CREATE MATERIALIZED VIEW mv1
           BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL
           DISTRIBUTED BY RANDOM BUCKETS 2
           PROPERTIES ('replication_num' = '1') 
           AS
           select *
           from (
           select 
           o_orderkey,
           FIRST_VALUE(o_custkey) OVER (
                   PARTITION BY o_orderdate 
                   ORDER BY o_totalprice NULLS LAST
                   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
               ) AS first_value,
           RANK() OVER (
                   PARTITION BY o_orderdate, o_orderstatus 
                   ORDER BY o_totalprice NULLS LAST
                   RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
               ) AS rank_value,
           LAG(l_extendedprice, 1, 0) over (partition by o_orderdate, 
l_shipdate order by l_quantity) AS lag_value 
           from 
           lineitem2
           left join orders2 on l_orderkey = o_orderkey and l_shipdate = 
o_orderdate
           ) t
           where o_orderkey > 1;
   ```
   
   if query as following, this can use mv to represent query
   ```sql
   select *
               from (
               select 
               o_orderkey,
               FIRST_VALUE(o_custkey) OVER (
                       PARTITION BY o_orderdate 
                       ORDER BY o_totalprice NULLS LAST
                       RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
                   ) AS first_value,
               RANK() OVER (
                       PARTITION BY o_orderdate, o_orderstatus 
                       ORDER BY o_totalprice NULLS LAST
                       RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
                   ) AS rank_value,
               LAG(l_extendedprice, 1, 0) over (partition by o_orderdate, 
l_shipdate order by l_quantity) AS lag_value 
               from 
               lineitem2
               left join orders2 on l_orderkey = o_orderkey and l_shipdate = 
o_orderdate
               ) t
               where o_orderkey > 2;
   ```
   explain result is as follwing:
   ```text
   
+----------------------------------------------------------------------------------------+
   | Explain String(Nereids Planner)                                            
            |
   
+----------------------------------------------------------------------------------------+
   | PLAN FRAGMENT 0                                                            
            |
   |   OUTPUT EXPRS:                                                            
            |
   |     o_orderkey[#4]                                                         
            |
   |     first_value[#5]                                                        
            |
   |     rank_value[#6]                                                         
            |
   |     lag_value[#7]                                                          
            |
   |   PARTITION: RANDOM                                                        
            |
   |                                                                            
            |
   |   HAS_COLO_PLAN_NODE: false                                                
            |
   |                                                                            
            |
   |   VRESULT SINK                                                             
            |
   |      MYSQL_PROTOCAL                                                        
            |
   |                                                                            
            |
   |   0:VOlapScanNode(445)                                                     
            |
   |      TABLE: regression_test_nereids_rules_p0_mv_window.mv1(mv1), 
PREAGGREGATION: ON    |
   |      PREDICATES: (o_orderkey[#0] > 2)                                      
            |
   |      partitions=1/1 (mv1)                                                  
            |
   |      tablets=2/2, tabletList=1755678381149,1755678381151                   
            |
   |      cardinality=1, avgRowSize=0.0, numNodes=1                             
            |
   |      pushAggOp=NONE                                                        
            |
   |      final projections: o_orderkey[#0], first_value[#1], rank_value[#2], 
lag_value[#3] |
   |      final project output tuple id: 1                                      
            |
   |                                                                            
            |
   |                                                                            
            |
   | ========== MATERIALIZATIONS ==========                                     
            |
   |                                                                            
            |
   | MaterializedView                                                           
            |
   | MaterializedViewRewriteSuccessAndChose:                                    
            |
   |   internal.regression_test_nereids_rules_p0_mv_window.mv1 chose            
            |
   |                                                                            
            |
   | MaterializedViewRewriteSuccessButNotChose:                                 
            |
   |                                                                            
            |
   | MaterializedViewRewriteFail:                                               
            |
   |                                                                            
            |
   |                                                                            
            |
   | ========== STATISTICS ==========                                           
            |
   | planed with unknown column statistics                                      
            |
   
+----------------------------------------------------------------------------------------+
   ```
   
   Issue Number: close #xxx
   
   Related PR: #xxx
   
   Problem Summary:
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [x] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to