查询视图,条件无法完全下推

Viewed 11

在使用复杂语句时,特别是多表关联查询语句, 部分条件无法下推到表

视图语句为:

CREATE OR REPLACE VIEW dwd_simplified_view AS
WITH area_car AS (
    SELECT
        a1.dt,
        a1.hphm,
        a1.gbbm AS kkdwbh
    FROM
        dwd_dlyx_kk_pass_data a1
        LEFT JOIN (
            SELECT *
            FROM (
                SELECT *, row_number() OVER (PARTITION BY hphm, hpzl ORDER BY ccdjrq DESC) AS nums
                FROM dwd_wp_jdcjcxx_df
            ) a1
            WHERE a1.nums = 1
        ) a2 ON a1.hphm = a2.hphm AND a1.hpzl = a2.hpzl
)
SELECT
    area_car.dt,
    area_car.hphm,
    area_car.kkdwbh
FROM
    area_car
LEFT JOIN (
    SELECT
        a1.dt,
        a1.hphm,
        a1.gbbm AS kkdwbh
    FROM
        dwd_dlyx_kk_pass_data a1
        LEFT JOIN (
            SELECT *
            FROM (
                SELECT *, row_number() OVER (PARTITION BY hphm, hpzl ORDER BY ccdjrq DESC) AS nums
                FROM dwd_wp_jdcjcxx_df
            ) a1
            WHERE a1.nums = 1
        ) a2 ON a1.hphm = a2.hphm AND a1.hpzl = a2.hpzl
) additional_data ON area_car.hphm = additional_data.hphm;

dwd_dlyx_kk_pass_data 为分区表,
调用视图方法的语句为:select * from dwd_simplified_view where dt < '2025-05-01';

其中有一部分无法下推时间。有没有通用的方法,可以能够将视图的时间下推到语句中。若不行的话,有没有类似自定义函数,将时间传参的方式实现该部分逻辑。

具体的执行计划如下:

mysql> explain select * from dwd_simplified_view where dt < '2025-05-01';
+-----------------------------------------------------------------------------------------------------------                                                                                                  -----------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                                                                                                                                                                                                                |
+-----------------------------------------------------------------------------------------------------------                                                                                                  -----------------------------------------------------------------------------------+
| PLAN FRAGMENT 0                                                                                                                                                                                                                                                                                
|   OUTPUT EXPRS:                                                                                                                                                                                                                                                                                
|     dt[#372]                                                                                                                                                                                                                                                                                   
|     hphm[#373]                                                                                                                                                                                                                                                                                 
|     kkdwbh[#374]                                                                                                                                                                                                                                                                               
|   PARTITION: UNPARTITIONED                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   VRESULT SINK                                                                                                                                                                                                                                                                                 
|      MYSQL_PROTOCAL                                                                                                                                                                                                                                                                            
|   19:VEXCHANGE                                                                                                                                                                                                                                                                                 
|      offset: 0                                                                                                                                                                                                                                                                                 
|      distribute expr lists: hphm[#373]                                                                                                                                                                                                                                                         
| PLAN FRAGMENT 1                                                                                                                                                                                                                                                                                
|   PARTITION: HASH_PARTITIONED: hphm[#367]                                                                                                                                                                                                                                                      
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 19                                                                                                                                                                                                                                                                            
|     UNPARTITIONED                                                                                                                                                                                                                                                                              
|   18:VHASH JOIN(1657)                                                                                                                                                                                                                                                                          
|   |  join op: RIGHT OUTER JOIN(PARTITIONED)[]                                                                                                                                                                                                                                                  
|   |  equal join conjunct: (hphm[#367] = hphm[#185])                                                                                                                                                                                                                                            
|   |  runtime filters: RF000[min_max] <- hphm[#185](114/128/1048576), RF001[bloom] <- hphm[#185](114/128/10                                                                                                  48576)                                                                             |
|   |  cardinality=2,230,874,521,638,496                                                                                                                                                                                                                                                         
|   |  vec output tuple id: 21                                                                                                                                                                                                                                                                   
|   |  output tuple id: 21                                                                                                                                                                                                                                                                       
|   |  vIntermediate tuple ids: 20                                                                                                                                                                                                                                                               
|   |  hash output slot ids: 184 185 186                                                                                                                                                                                                                                                         
|   |  final projections: dt[#369], hphm[#370], kkdwbh[#371]                                                                                                                                                                                                                                     
|   |  final project output tuple id: 21                                                                                                                                                                                                                                                         
|   |  distribute expr lists: hphm[#367]                                                                                                                                                                                                                                                         
|   |  distribute expr lists: hphm[#185]                                                                                                                                                                                                                                                         
|   |                                                                                                                                                                                                                                                                                            
|   |----8:VEXCHANGE                                                                                                                                                                                                                                                                             
|   |       offset: 0                                                                                                                                                                                                                                                                            
|   |       distribute expr lists:                                                                                                                                                                                                                                                               
|   |                                                                                                                                                                                                                                                                                            
|   17:VEXCHANGE                                                                                                                                                                                                                                                                                 
|      offset: 0                                                                                                                                                                                                                                                                                 
|      distribute expr lists:                                                                                                                                                                                                                                                                    
| PLAN FRAGMENT 2                                                                                                                                                                                                                                                                                
|   PARTITION: RANDOM                                                                                                                                                                                                                                                                            
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 17                                                                                                                                                                                                                                                                            
|     HASH_PARTITIONED: hphm[#367]                                                                                                                                                                                                                                                               
|   16:VHASH JOIN(1570)                                                                                                                                                                                                                                                                          
|   |  join op: LEFT OUTER JOIN(BROADCAST)[]                                                                                                                                                                                                                                                     
|   |  equal join conjunct: (hphm[#361] = hphm[#341])                                                                                                                                                                                                                                            
|   |  equal join conjunct: (hpzl[#362] = hpzl[#340])                                                                                                                                                                                                                                            
|   |  cardinality=770,332,800                                                                                                                                                                                                                                                                   
|   |  vec output tuple id: 19                                                                                                                                                                                                                                                                   
|   |  output tuple id: 19                                                                                                                                                                                                                                                                       
|   |  vIntermediate tuple ids: 18                                                                                                                                                                                                                                                               
|   |  hash output slot ids: 361                                                                                                                                                                                                                                                                 
|   |  final projections: hphm[#363]                                                                                                                                                                                                                                                             
|   |  final project output tuple id: 19                                                                                                                                                                                                                                                         
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |                                                                                                                                                                                                                                                                                            
|   |----14:VEXCHANGE                                                                                                                                                                                                                                                                            
|   |       offset: 0                                                                                                                                                                                                                                                                            
|   |       distribute expr lists: hphm[#341], hpzl[#340]                                                                                                                                                                                                                                        
|   |                                                                                                                                                                                                                                                                                            
|   15:VOlapScanNode(1514)                                                                                                                                                                                                                                                                       
|      TABLE: nbjg.dwd_dlyx_kk_pass_data(dwd_dlyx_kk_pass_data), PREAGGREGATION: ON                                                                                                                                                                                                              
|      runtime filters: RF000[min_max] -> hphm[#348], RF001[bloom] -> hphm[#348]                                                                                                                                                                                                                 
|      partitions=15/62 (P_20250425,P_20250426,P_20250427,P_20250428,P_20250429,P_20250430,P_20250501,P_20250502,P_20250503,P_20250504,P_20250505,P_20250506,P_20250507,P_20250508,P_20250509)|
|      tablets=150/150, tabletList=60807,60811,60815 ...                                                                                                                                                                                                                                         
|      cardinality=770332800, avgRowSize=0.0, numNodes=1                                                                                                                                                                                                                                         
|      pushAggOp=NONE                                                                                                                                                                                                                                                                            
|      final projections: hphm[#348], hpzl[#349]                                                                                                                                                                                                                                                 
|      final project output tuple id: 17                                                                                                                                                                                                                                                         
| PLAN FRAGMENT 3                                                                                                                                                                                                                                                                                
|   PARTITION: HASH_PARTITIONED: hphm[#334], hpzl[#333]                                                                                                                                                                                                                                          
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 14                                                                                                                                                                                                                                                                            
|     UNPARTITIONED                                                                                                                                                                                                                                                                              
|   13:VANALYTIC(1550)                                                                                                                                                                                                                                                                           
|   |  functions: [row_number()]                                                                                                                                                                                                                                                                 
|   |  partition by: hphm[#337], hpzl[#336]                                                                                                                                                                                                                                                      
|   |  order by: ccdjrq[#338] DESC NULLS LAST                                                                                                                                                                                                                                                    
|   |  window: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW                                                                                                                                                                                                                                  
|   |  predicates: (nums[#339] = 1)                                                                                                                                                                                                                                                              
|   |  final projections: hpzl[#336], hphm[#337]                                                                                                                                                                                                                                                 
|   |  final project output tuple id: 15                                                                                                                                                                                                                                                         
|   |  distribute expr lists: hphm[#337], hpzl[#336]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
|   12:VSORT(1545)                                                                                                                                                                                                                                                                               
|   |  order by: hphm[#337] ASC, hpzl[#336] ASC, ccdjrq[#338] DESC                                                                                                                                                                                                                               
|   |  offset: 0                                                                                                                                                                                                                                                                                 
|   |  distribute expr lists: hphm[#334], hpzl[#333]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
|   11:VEXCHANGE                                                                                                                                                                                                                                                                                 
|      offset: 0                                                                                                                                                                                                                                                                                 
|      distribute expr lists:                                                                                                                                                                                                                                                                    
| PLAN FRAGMENT 4                                                                                                                                                                                                                                                                                
|   PARTITION: HASH_PARTITIONED: jdcxh[#187]                                                                                                                                                                                                                                                     
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 11                                                                                                                                                                                                                                                                            
|     HASH_PARTITIONED: hphm[#334], hpzl[#333]                                                                                                                                                                                                                                                   
|   10:VPartitionTopN(1535)                                                                                                                                                                                                                                                                      
|   |  functions: row_number                                                                                                                                                                                                                                                                     
|   |  partition by: hphm[#331], hpzl[#330]                                                                                                                                                                                                                                                      
|   |  order by: ccdjrq[#335] DESC                                                                                                                                                                                                                                                               
|   |  has global limit: false                                                                                                                                                                                                                                                                   
|   |  partition limit: 1                                                                                                                                                                                                                                                                        
|   |  partition topn phase: TWO_PHASE_LOCAL_PTOPN                                                                                                                                                                                                                                               
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |                                                                                                                                                                                                                                                                                            
|   9:VOlapScanNode(1520)                                                                                                                                                                                                                                                                        
|      TABLE: nbjg.dwd_wp_jdcjcxx_df(dwd_wp_jdcjcxx_df), PREAGGREGATION: ON                                                                                                                                                                                                                      
|      PREDICATES: (__DORIS_DELETE_SIGN__[#328] = 0)                                                                                                                                                                                                                                             
|      partitions=1/1 (dwd_wp_jdcjcxx_df)                                                                                                                                                                                                                                                        
|      tablets=12/12, tabletList=41927,41931,41935 ...                                                                                                                                                                                                                                           
|      cardinality=115, avgRowSize=0.0, numNodes=1                                                                                                                                                                                                                                               
|      pushAggOp=NONE                                                                                                                                                                                                                                                                            
|      final projections: hpzl[#188], hphm[#189], ccdjrq[#207]                                                                                                                                                                                                                                   
|      final project output tuple id: 11                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
| PLAN FRAGMENT 5                                                                                                                                                                                                                                                                                
|   PARTITION: RANDOM                                                                                                                                                                                                                                                                            
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 08                                                                                                                                                                                                                                                                            
|     HASH_PARTITIONED: hphm[#185]                                                                                                                                                                                                                                                               
|   7:VHASH JOIN(1642)                                                                                                                                                                                                                                                                           
|   |  join op: LEFT OUTER JOIN(BROADCAST)[]                                                                                                                                                                                                                                                     
|   |  equal join conjunct: (hphm[#176] = hphm[#154])                                                                                                                                                                                                                                            
|   |  equal join conjunct: (hpzl[#174] = hpzl[#153])                                                                                                                                                                                                                                            
|   |  cardinality=330,142,628                                                                                                                                                                                                                                                                   
|   |  vec output tuple id: 9                                                                                                                                                                                                                                                                    
|   |  output tuple id: 9                                                                                                                                                                                                                                                                        
|   |  vIntermediate tuple ids: 8                                                                                                                                                                                                                                                                
|   |  hash output slot ids: 176 177 175                                                                                                                                                                                                                                                         
|   |  final projections: dt[#181], hphm[#180], kkdwbh[#179]                                                                                                                                                                                                                                     
|   |  final project output tuple id: 9                                                                                                                                                                                                                                                          
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |                                                                                                                                                                                                                                                                                            
|   |----5:VEXCHANGE                                                                                                                                                                                                                                                                             
|   |       offset: 0                                                                                                                                                                                                                                                                            
|   |       distribute expr lists: hphm[#154], hpzl[#153]                                                                                                                                                                                                                                        
|   |                                                                                                                                                                                                                                                                                            
|   6:VOlapScanNode(1581)                                                                                                                                                                                                                                                                        
|      TABLE: nbjg.dwd_dlyx_kk_pass_data(dwd_dlyx_kk_pass_data), PREAGGREGATION: ON                                                                                                                                                                                                              
|      PREDICATES: (dt[#173] < '2025-05-01 00:00:00')                                                                                                                                                                                                                                            
|      partitions=6/62 (P_20250425,P_20250426,P_20250427,P_20250428,P_20250429,P_20250430)                                                                                                                                                                                                       
|      tablets=60/60, tabletList=60438,60442,60446 ...                                                                                                                                                                                                                                           
|      cardinality=300124800, avgRowSize=0.0, numNodes=1                                                                                                                                                                                                                                         
|      pushAggOp=NONE                                                                                                                                                                                                                                                                            
|      final projections: hpzl[#162], gbbm[#156], hphm[#161], dt[#173]                                                                                                                                                                                                                           
|      final project output tuple id: 7                                                                                                                                                                                                                                                          
| PLAN FRAGMENT 6                                                                                                                                                                                                                                                                                
|   PARTITION: HASH_PARTITIONED: hphm[#147], hpzl[#146]                                                                                                                                                                                                                                          
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 05                                                                                                                                                                                                                                                                            
|     UNPARTITIONED                                                                                                                                                                                                                                                                              
|   4:VANALYTIC(1622)                                                                                                                                                                                                                                                                            
|   |  functions: [row_number()]                                                                                                                                                                                                                                                                 
|   |  partition by: hphm[#150], hpzl[#149]                                                                                                                                                                                                                                                      
|   |  order by: ccdjrq[#151] DESC NULLS LAST                                                                                                                                                                                                                                                    
|   |  window: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW                                                                                                                                                                                                                                  
|   |  predicates: (nums[#152] = 1)                                                                                                                                                                                                                                                              
|   |  final projections: hpzl[#149], hphm[#150]                                                                                                                                                                                                                                                 
|   |  final project output tuple id: 5                                                                                                                                                                                                                                                          
|   |  distribute expr lists: hphm[#150], hpzl[#149]                                                                                                                                                                                                                                             
|   |                                                                                                                                                                                                                                                                                            
|   3:VSORT(1617)                                                                                                                                                                                                                                                                                
|   |  order by: hphm[#150] ASC, hpzl[#149] ASC, ccdjrq[#151] DESC                                                                                                                                                                                                                               
|   |  offset: 0                                                                                                                                                                                                                                                                                 
|   |  distribute expr lists: hphm[#147], hpzl[#146]                                                                                                                                                                                                                                             
|   |                                                                                                                                                                                                                                                                                            
|   2:VEXCHANGE                                                                                                                                                                                                                                                                                  
|      offset: 0                                                                                                                                                                                                                                                                                 
|      distribute expr lists:                                                                                                                                                                                                                                                                    
| PLAN FRAGMENT 7                                                                                                                                                                                                                                                                                
|   PARTITION: HASH_PARTITIONED: jdcxh[#0]                                                                                                                                                                                                                                                       
|   HAS_COLO_PLAN_NODE: false                                                                                                                                                                                                                                                                    
|   STREAM DATA SINK                                                                                                                                                                                                                                                                             
|     EXCHANGE ID: 02                                                                                                                                                                                                                                                                            
|     HASH_PARTITIONED: hphm[#147], hpzl[#146]                                                                                                                                                                                                                                                   
|   1:VPartitionTopN(1607)                                                                                                                                                                                                                                                                       
|   |  functions: row_number                                                                                                                                                                                                                                                                     
|   |  partition by: hphm[#144], hpzl[#143]                                                                                                                                                                                                                                                      
|   |  order by: ccdjrq[#148] DESC                                                                                                                                                                                                                                                               
|   |  has global limit: false                                                                                                                                                                                                                                                                   
|   |  partition limit: 1                                                                                                                                                                                                                                                                        
|   |  partition topn phase: TWO_PHASE_LOCAL_PTOPN                                                                                                                                                                                                                                               
|   |  distribute expr lists:                                                                                                                                                                                                                                                                    
|   |                                                                                                                                                                                                                                                                                            
|   0:VOlapScanNode(1592)                                                                                                                                                                                                                                                                        
|      TABLE: nbjg.dwd_wp_jdcjcxx_df(dwd_wp_jdcjcxx_df), PREAGGREGATION: ON                                                                                                                                                                                                                      
|      PREDICATES: (__DORIS_DELETE_SIGN__[#141] = 0)                                                                                                                                                                                                                                             
|      partitions=1/1 (dwd_wp_jdcjcxx_df)                                                                                                                                                                                                                                                        
|      tablets=12/12, tabletList=41927,41931,41935 ...                                                                                                                                                                                                                                           
|      cardinality=115, avgRowSize=0.0, numNodes=1                                                                                                                                                                                                                                               
|      pushAggOp=NONE                                                                                                                                                                                                                                                                            
|      final projections: hpzl[#1], hphm[#2], ccdjrq[#20]                                                                                                                                                                                                                                        
|      final project output tuple id: 1
```
0 Answers