gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

Add support for Planhints logging

Open Sanath97 opened this issue 1 year ago • 10 comments

Add support for plan hints logging. This commit supports logging of Used and Un-Used Scan, Row and JoinOrder Hints types. Below is a snippet of how this can be used/looks like:

SET client_min_messages TO LOG;
/*+
    IndexScan(t1 my_incredible_index)
    IndexScan(t3 our_amazing_index)
*/
EXPLAIN (costs off) SELECT t1.a, t2.a, t3.a FROM my_table AS t1 JOIN
your_table AS t2 ON t1.a=t2.a JOIN our_table AS t3 ON t3.a=t2.a WHERE
t1.a<42;
LOG:  statement: 
    IndexScan(t1 my_incredible_index)
    IndexScan(t3 our_amazing_index)
EXPLAIN (costs off) SELECT t1.a, t2.a, t3.a FROM my_table AS t1 JOIN
your_table AS t2 ON t1.a=t2.a JOIN our_table AS t3 ON t3.a=t2.a WHERE
t1.a<42;
LOG:  2024-04-25 10:21:22:363407 CDT,THD000,TRACE,"PlanHint: [
Used Hints:
ScanHint: t1[indexes:my_incredible_index types:IndexScan]
ScanHint: t3[indexes:our_amazing_index types:IndexScan]
Un-Used Hints:
]",

                                 QUERY PLAN
-----------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: (t2.a = t3.a)
         ->  Nested Loop
               Join Filter: true
               ->  Index Only Scan using your_awesome_index on
your_table t2yml                     Index Cond: (a < 42)
               ->  Index Scan using my_incredible_index on my_table t1
                     Index Cond: ((a = t2.a) AND (a < 42))
         ->  Hash
               ->  Dynamic Index Scan on our_amazing_index on our_table
t3
                     Index Cond: (a < 42)
                     Number of partitions to scan: 4 (out of 4)
 Optimizer: GPORCA
(14 rows)

Sanath97 avatar Apr 25 '24 16:04 Sanath97