Skip to content

Introduce a session property to print the before and after plan node of specified optimizations#20035

Merged
mlyublena merged 1 commit intoprestodb:masterfrom
mlyublena:optimizer-before-and-after
Jul 13, 2023
Merged

Introduce a session property to print the before and after plan node of specified optimizations#20035
mlyublena merged 1 commit intoprestodb:masterfrom
mlyublena:optimizer-before-and-after

Conversation

@mlyublena
Copy link
Contributor

@mlyublena mlyublena commented Jun 30, 2023

Introduce a new session property verbose_optimizer_results with possible values
'ALL' | 'NONE' | <OptimizerClassName> [,<OptimizerClassName>...]

When enabled, the 'before' and 'after' for selected optimizations will be printed at the end of the explain plan. When 'ALL' is specified, it will print the result of every applicable optimizer.

For example:

presto:tpch  explain select commitdate, count(*) from lineitem group by commitdate;
                                                                                                                                                                                                                                                                                                                                                                             
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
 - Output[commitdate, _col1] =  [commitdate:date, count:bigint]                                                                                                                                                                                                                                                                                                              
         _col1 := count (1:28)                                                                                                                                                                                                                                                                                                                                               
     - RemoteStreamingExchange[GATHER] =  [commitdate:date, count:bigint]                                                                                                                                                                                                                                                                                                    
         - Project[projectLocality = LOCAL] =  [commitdate:date, count:bigint]                                                                                                                                                                                                                                                                                               
             - Aggregate(FINAL)[commitdate][$hashvalue] =  [commitdate:date, $hashvalue:bigint, count:bigint]                                                                                                                                                                                                                                                                
                     count := "presto.default.count"((count_8)) (1:28)                                                                                                                                                                                                                                                                                                       
                 - LocalExchange[HASH][$hashvalue] (commitdate) =  [commitdate:date, count_8:bigint, $hashvalue:bigint]                                                                                                                                                                                                                                                      
                     - RemoteStreamingExchange[REPARTITION][$hashvalue_9] =  [commitdate:date, count_8:bigint, $hashvalue_9:bigint]                                                                                                                                                                                                                                          
                         - Aggregate(PARTIAL)[commitdate][$hashvalue_10] =  [commitdate:date, $hashvalue_10:bigint, count_8:bigint]                                                                                                                                                                                                                                          
                                 count_8 := "presto.default.count"(*) (1:28)                                                                                                                                                                                                                                                                                                 
                             - ScanProject[table = TableHandle {connectorId='hive', connectorHandle='HiveTableHandle{schemaName=tpch, tableName=lineitem, analyzePartitionValues=Optional.empty}', layout='Optional[tpch.lineitem{}]'}, projectLocality = LOCAL] =  [commitdate:date, $hashvalue_10:bigint]                                                                  
                                     Estimates: {rows: 60175 (822.71kB), cpu: 300875.00, memory: 0.00, network: 0.00}/{rows: 60175 (822.71kB), cpu: 1143325.00, memory: 0.00, network: 0.00}                                                                                                                                                                                 
                                     $hashvalue_10 := combine_hash(BIGINT'0', COALESCE($operator$hash_code(commitdate), BIGINT'0')) (1:60)                                                                                                                                                                                                                                   
                                     LAYOUT: tpch.lineitem{}                                                                                                                                                                                                                                                                                                                 
                                     commitdate := commitdate:date:11:REGULAR (1:42)                                                                                                                                                                                                                                                                                         

 PruneTableScanColumns (before):                                                                                                                                                                                                                                                                                                                                             
 - Project[projectLocality = UNKNOWN] =  [commitdate_0:date]                                                                                                                                                                                                                                                                                                                 
         commitdate_0 := commitdate (1:43)                                                                                                                                                                                                                                                                                                                                   
     - GroupReference[9] =  [orderkey:bigint, partkey:bigint, suppkey:bigint, linenumber:integer, quantity:double, extendedprice:double, discount:double, tax:double, returnflag:varchar(1), linestatus:varchar(1), shipdate:date, commitdate:date, receiptdate:date, shipinstruct:varchar(25), shipmode:varchar(10), comment:varchar(44), $path:varchar, $file_size:bigint, 

 PruneTableScanColumns (after):                                                                                                                                                                                                                                                                                                                                              
 - ScanProject[table = TableHandle {connectorId='hive', connectorHandle='HiveTableHandle{schemaName=tpch, tableName=lineitem, analyzePartitionValues=Optional.empty}', layout='Optional.empty'}, projectLocality = UNKNOWN] =  [commitdate_0:date]                                                                                                                           
         commitdate_0 := commitdate (1:43)                                                                                                                                                                                                                                                                                                                                   
         commitdate := commitdate:date:11:REGULAR (1:42)                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                             
...
                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                             
 PushPartialAggregationThroughExchange (before):                                                                                                                                                                                                                                                                                                                             
 - Aggregate[commitdate] =  [commitdate:date, count:bigint]                                                                                                                                                                                                                                                                                                                  
         count := "presto.default.count"(*) (1:28)                                                                                                                                                                                                                                                                                                                           
     - GroupReference[4] =  [commitdate:date]                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                             
 PushPartialAggregationThroughExchange (after):                                                                                                                                                                                                                                                                                                                              
 - Aggregate(FINAL)[commitdate] =  [commitdate:date, count:bigint]                                                                                                                                                                                                                                                                                                           
         count := "presto.default.count"((count_8)) (1:28)                                                                                                                                                                                                                                                                                                                   
     - Aggregate(PARTIAL)[commitdate] =  [commitdate:date, count_8:bigint]                                                                                                                                                                                                                                                                                                   
             count_8 := "presto.default.count"(*) (1:28)                                                                                                                                                                                                                                                                                                                     
         - GroupReference[4] =  [commitdate:date]                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                             
 PushPartialAggregationThroughExchange (before):                                                                                                                                                                                                                                                                                                                             
 - Aggregate(PARTIAL)[commitdate] =  [commitdate:date, count_8:bigint]                                                                                                                                                                                                                                                                                                       
         count_8 := "presto.default.count"(*) (1:28)                                                                                                                                                                                                                                                                                                                         
     - GroupReference[4] =  [commitdate:date]                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                             
 PushPartialAggregationThroughExchange (after):                                                                                                                                                                                                                                                                                                                              
 - LocalExchange[HASH] (commitdate) =  [commitdate:date, count_8:bigint]                                                                                                                                                                                                                                                                                                     
     - Project[projectLocality = LOCAL] =  [commitdate:date, count_8:bigint]                                                                                                                                                                                                                                                                                                 
         - Aggregate(PARTIAL)[commitdate] =  [commitdate:date, count_8:bigint]                                                                                                                                                                                                                                                                                               
                 count_8 := "presto.default.count"(*) (1:28)                                                                                                                                                                                                                                                                                                                 
             - GroupReference[5] =  [commitdate:date]
(1 row)

@mlyublena mlyublena changed the title Introduce a session property to print the before and after plan node … Introduce a session property to print the before and after plan node of specified optimizations Jun 30, 2023
@mlyublena mlyublena force-pushed the optimizer-before-and-after branch 2 times, most recently from fb531a7 to 6bdf240 Compare June 30, 2023 23:34
@mlyublena mlyublena force-pushed the optimizer-before-and-after branch 3 times, most recently from 2980bd0 to 9a95c63 Compare July 10, 2023 21:30
@mlyublena mlyublena marked this pull request as ready for review July 10, 2023 21:31
@mlyublena mlyublena requested a review from a team as a code owner July 10, 2023 21:31
Copy link
Contributor

@feilong-liu feilong-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this only targets iterative optimizer rule, is this correct?

@mlyublena mlyublena force-pushed the optimizer-before-and-after branch from 9a95c63 to 2e22307 Compare July 10, 2023 22:57
@mlyublena
Copy link
Contributor Author

My understanding is that this only targets iterative optimizer rule, is this correct?

No, also the plan optimizers.
I just updated collectOptimizerInformation in Optimizer.java to do this

@mlyublena mlyublena force-pushed the optimizer-before-and-after branch from 2e22307 to 92a05f5 Compare July 10, 2023 23:26
@mlyublena mlyublena requested a review from pranjalssh July 12, 2023 16:29
@mlyublena mlyublena force-pushed the optimizer-before-and-after branch from 92a05f5 to c9f8363 Compare July 13, 2023 17:08
…of specified optimizations

Introduce a new session property verbose_optimizer_results with possible values 'ALL' | 'NONE' | <OptimizerClassName>[,<OptimizerClassName>...]

When enabled, the 'before' and 'after' for selected optimizations will be printed at the end of the explain plan.
When 'ALL' is specified, it will print the result of every applicable optimizer.
@mlyublena mlyublena force-pushed the optimizer-before-and-after branch from c9f8363 to 30b6a24 Compare July 13, 2023 17:39
@mlyublena mlyublena merged commit 66c897a into prestodb:master Jul 13, 2023
@wanglinsong wanglinsong mentioned this pull request Jul 27, 2023
28 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