Skip to content

Convert values node followed by false filter to empty values node#21275

Merged
NikhilCollooru merged 1 commit intoprestodb:masterfrom
feilong-liu:filter_values
Nov 1, 2023
Merged

Convert values node followed by false filter to empty values node#21275
NikhilCollooru merged 1 commit intoprestodb:masterfrom
feilong-liu:filter_values

Conversation

@feilong-liu
Copy link
Contributor

Description

Run RemoveTrivialFilters after simplifyRowExpressionOptimizer, so that queries like select * from (values 1, 2) t(k) where 1=0 will be simplified as empty values node.

Motivation and Context

Values node followed by false filter is not optimized:

presto:tpch> explain (type distributed) select * from (values 1, 2) t(k) where 1=0;
                                                       Query Plan                                                        
-------------------------------------------------------------------------------------------------------------------------
 Fragment 0 [SINGLE]                                                                                                     
     Output layout: [field]                                                                                              
     Output partitioning: SINGLE []                                                                                      
     Stage Execution Strategy: UNGROUPED_EXECUTION                                                                       
     - Output[PlanNodeId 9][k] => [field:integer]                                                                        
             Estimates: {source: CostBasedSourceInfo, rows: 0 (0B), cpu: 20.00, memory: 0.00, network: 0.00}             
             k := field (1:28)                                                                                           
         - Filter[PlanNodeId 4][filterPredicate = BOOLEAN'false'] => [field:integer]                                     
                 Estimates: {source: CostBasedSourceInfo, rows: 0 (0B), cpu: 20.00, memory: 0.00, network: 0.00}         
             - LocalExchange[PlanNodeId 184][ROUND_ROBIN] () => [field:integer]                                          
                     Estimates: {source: CostBasedSourceInfo, rows: 2 (10B), cpu: 10.00, memory: 0.00, network: 0.00}    
                 - Values[PlanNodeId 0] => [field:integer]                                                               
                         Estimates: {source: CostBasedSourceInfo, rows: 2 (10B), cpu: 0.00, memory: 0.00, network: 0.00} 
                         (INTEGER'1')                                                                                    
                         (INTEGER'2')                                                                                    
                                                                                                                         
                                                                                                                         
(1 row)

With the change here:

presto:tpch> explain (type distributed) select * from (values 1, 2) t(k) where 1=0;
                                                   Query Plan                                                   
----------------------------------------------------------------------------------------------------------------
 Fragment 0 [SINGLE]                                                                                            
     Output layout: [field_1]                                                                                   
     Output partitioning: SINGLE []                                                                             
     Stage Execution Strategy: UNGROUPED_EXECUTION                                                              
     - Output[PlanNodeId 9][k] => [field_1:integer]                                                             
             Estimates: {source: CostBasedSourceInfo, rows: 0 (0B), cpu: 0.00, memory: 0.00, network: 0.00}     
             k := field_1 (1:28)                                                                                
         - Values[PlanNodeId 83] => [field_1:integer]                                                           
                 Estimates: {source: CostBasedSourceInfo, rows: 0 (0B), cpu: 0.00, memory: 0.00, network: 0.00} 
                                                                                                                
                                                                                                                
(1 row)

The following SimplifyPlanWithEmptyInput can further simplify the empty value nodes.

Impact

Better performance

Test Plan

Easy change

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* Enable optimization of values node followed by false filter to empty values node

@NikhilCollooru NikhilCollooru merged commit 66aab8b into prestodb:master Nov 1, 2023
@wanglinsong wanglinsong mentioned this pull request Dec 8, 2023
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants