OSDN Git Service

Support PostgreSQL 14
[pghintplan/pg_hint_plan.git] / expected / pg_hint_plan.out
index e95f0af..5148f6a 100644 (file)
@@ -13,12 +13,13 @@ EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.val = t2.val;
                 QUERY PLAN                 
 -------------------------------------------
- Merge Join
-   Merge Cond: (t2.val = t1.val)
-   ->  Index Scan using t2_val on t2
-   ->  Materialize
+ Nested Loop
+   ->  Seq Scan on t2
+   ->  Memoize
+         Cache Key: t2.val
          ->  Index Scan using t1_val on t1
-(5 rows)
+               Index Cond: (val = t2.val)
+(6 rows)
 
 LOAD 'pg_hint_plan';
 SET pg_hint_plan.debug_print TO on;
@@ -34,12 +35,13 @@ EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.val = t2.val;
                 QUERY PLAN                 
 -------------------------------------------
- Merge Join
-   Merge Cond: (t2.val = t1.val)
-   ->  Index Scan using t2_val on t2
-   ->  Materialize
+ Nested Loop
+   ->  Seq Scan on t2
+   ->  Memoize
+         Cache Key: t2.val
          ->  Index Scan using t1_val on t1
-(5 rows)
+               Index Cond: (val = t2.val)
+(6 rows)
 
 /*+ Test (t1 t2) */
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
@@ -224,7 +226,7 @@ error hint:
 /*+Set(work_mem "1M")*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 INFO:  invalid value for parameter "work_mem": "1M"
-HINT:  Valid units for this parameter are "kB", "MB", "GB", and "TB".
+HINT:  Valid units for this parameter are "B", "kB", "MB", "GB", and "TB".
 LOG:  pg_hint_plan:
 used hint:
 not used hint:
@@ -276,6 +278,21 @@ Set(work_mem TO 1MB)
    ->  Index Scan using t2_pkey on t2
 (4 rows)
 
+/*+SeqScan() */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near " "
+DETAIL:  SeqScan hint requires a relation.
+LOG:  pg_hint_plan:
+used hint:
+not used hint:
+duplication hint:
+error hint:
+SeqScan()
+
+ ?column? 
+----------
+        1
+(1 row)
+
 /*+SeqScan(t1 t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 INFO:  pg_hint_plan: hint syntax error at or near ""
@@ -445,6 +462,36 @@ error hint:
          Index Cond: (id = t1.id)
 (5 rows)
 
+/*+ NestLoop() */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near " "
+DETAIL:  NestLoop hint requires at least two relations.
+LOG:  pg_hint_plan:
+used hint:
+not used hint:
+duplication hint:
+error hint:
+NestLoop()
+
+ ?column? 
+----------
+        1
+(1 row)
+
+/*+ NestLoop(x) */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near " "
+DETAIL:  NestLoop hint requires at least two relations.
+LOG:  pg_hint_plan:
+used hint:
+not used hint:
+duplication hint:
+error hint:
+NestLoop(x)
+
+ ?column? 
+----------
+        1
+(1 row)
+
 /*+HashJoin(t1 t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 LOG:  pg_hint_plan:
@@ -1283,16 +1330,15 @@ error hint:
 (3 rows)
 
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+SeqScan(t1)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -1307,10 +1353,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Seq Scan on t1
          Filter: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+SeqScan(t2)*/
@@ -1428,10 +1474,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Seq Scan on t1
          Filter: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+SeqScan(t1) NoIndexScan(t2)*/
@@ -1448,10 +1494,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Seq Scan on t1
          Filter: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+SeqScan(t1) NoBitmapScan(t2)*/
@@ -1468,10 +1514,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Seq Scan on t1
          Filter: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+SeqScan(t1) NoTidScan(t2)*/
@@ -1488,10 +1534,10 @@ error hint:
 ---------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Seq Scan on t2
-         Filter: (ctid = '(1,1)'::tid)
    ->  Seq Scan on t1
          Filter: (ctid = '(1,1)'::tid)
+   ->  Seq Scan on t2
+         Filter: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+IndexScan(t1)*/
@@ -1946,10 +1992,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+TidScan(t2)*/
@@ -2067,10 +2113,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+TidScan(t1) NoIndexScan(t2)*/
@@ -2087,10 +2133,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+TidScan(t1) NoBitmapScan(t2)*/
@@ -2107,10 +2153,10 @@ error hint:
 -----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
-   ->  Tid Scan on t2
-         TID Cond: (ctid = '(1,1)'::tid)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
 (6 rows)
 
 /*+TidScan(t1) NoTidScan(t2)*/
@@ -2142,16 +2188,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoSeqScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2162,16 +2207,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoSeqScan(t1) SeqScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2265,16 +2309,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoSeqScan(t1) NoIndexScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2286,16 +2329,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoSeqScan(t1) NoBitmapScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2307,16 +2349,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoSeqScan(t1) NoTidScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2347,16 +2388,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoIndexScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2367,16 +2407,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoIndexScan(t1) SeqScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2470,16 +2509,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoIndexScan(t1) NoIndexScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2491,16 +2529,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoIndexScan(t1) NoBitmapScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2512,16 +2549,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoIndexScan(t1) NoTidScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2552,16 +2588,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoBitmapScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2572,16 +2607,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoBitmapScan(t1) SeqScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2675,16 +2709,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoBitmapScan(t1) NoIndexScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2696,16 +2729,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoBitmapScan(t1) NoBitmapScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2717,16 +2749,15 @@ not used hint:
 duplication hint:
 error hint:
 
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-(7 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+(6 rows)
 
 /*+NoBitmapScan(t1) NoTidScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)';
@@ -2950,18 +2981,17 @@ error hint:
 
 -- additional test
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)' AND t1.id < 10 AND t2.id < 10;
-                  QUERY PLAN                   
------------------------------------------------
+               QUERY PLAN                
+-----------------------------------------
  Nested Loop
    Join Filter: (t1.id = t2.id)
    ->  Tid Scan on t1
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: (id < 10)
-   ->  Materialize
-         ->  Tid Scan on t2
-               TID Cond: (ctid = '(1,1)'::tid)
-               Filter: (id < 10)
-(9 rows)
+   ->  Tid Scan on t2
+         TID Cond: (ctid = '(1,1)'::tid)
+         Filter: (id < 10)
+(8 rows)
 
 /*+BitmapScan(t1) BitmapScan(t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)' AND t2.ctid = '(1,1)' AND t1.id < 10 AND t2.id < 10;
@@ -3016,6 +3046,7 @@ error hint:
    ->  Index Scan using t2_pkey on t2
 (4 rows)
 
+-- Cannot work
 /*+NestLoop(t1 t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1 FULL OUTER JOIN  t2 ON (t1.id = t2.id);
 LOG:  pg_hint_plan:
@@ -3028,10 +3059,10 @@ error hint:
           QUERY PLAN          
 ------------------------------
  Hash Full Join
-   Hash Cond: (t2.id = t1.id)
-   ->  Seq Scan on t2
+   Hash Cond: (t1.id = t2.id)
+   ->  Seq Scan on t1
    ->  Hash
-         ->  Seq Scan on t1
+         ->  Seq Scan on t2
 (5 rows)
 
 -- inheritance tables test
@@ -3040,23 +3071,23 @@ EXPLAIN (COSTS false) SELECT * FROM p1 WHERE id >= 50 AND id <= 51 AND p1.ctid =
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
@@ -3065,13 +3096,13 @@ EXPLAIN (COSTS false) SELECT * FROM p1 WHERE id >= 50 AND id <= 51 AND p1.ctid =
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (9 rows)
 
@@ -3088,23 +3119,23 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
@@ -3117,34 +3148,34 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p1_pkey on p1
+   ->  Index Scan using p1_pkey on p1 p1_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_pkey on p1_c1
+   ->  Index Scan using p1_c1_pkey on p1_c1 p1_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c2_pkey on p1_c2
+   ->  Index Scan using p1_c2_pkey on p1_c2 p1_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c3_pkey on p1_c3
+   ->  Index Scan using p1_c3_pkey on p1_c3 p1_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c4_pkey on p1_c4
+   ->  Index Scan using p1_c4_pkey on p1_c4 p1_5
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1
+   ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1 p1_6
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2
+   ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2 p1_7
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c3_c1_pkey on p1_c3_c1
+   ->  Index Scan using p1_c3_c1_pkey on p1_c3_c1 p1_8
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c3_c2_pkey on p1_c3_c2
+   ->  Index Scan using p1_c3_c2_pkey on p1_c3_c2 p1_9
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (28 rows)
@@ -3161,47 +3192,47 @@ error hint:
                       QUERY PLAN                       
 -------------------------------------------------------
  Append
-   ->  Bitmap Heap Scan on p1
+   ->  Bitmap Heap Scan on p1 p1_1
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1
+   ->  Bitmap Heap Scan on p1_c1 p1_2
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c2
+   ->  Bitmap Heap Scan on p1_c2 p1_3
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c2_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c3
+   ->  Bitmap Heap Scan on p1_c3 p1_4
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c3_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c4
+   ->  Bitmap Heap Scan on p1_c4 p1_5
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c4_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1_c1
+   ->  Bitmap Heap Scan on p1_c1_c1 p1_6
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_c1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1_c2
+   ->  Bitmap Heap Scan on p1_c1_c2 p1_7
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_c2_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c3_c1
+   ->  Bitmap Heap Scan on p1_c3_c1 p1_8
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c3_c1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c3_c2
+   ->  Bitmap Heap Scan on p1_c3_c2 p1_9
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c3_c2_pkey
@@ -3220,31 +3251,31 @@ error hint:
                  QUERY PLAN                  
 ---------------------------------------------
  Append
-   ->  Tid Scan on p1
+   ->  Tid Scan on p1 p1_1
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1
+   ->  Tid Scan on p1_c1 p1_2
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c2
+   ->  Tid Scan on p1_c2 p1_3
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c3
+   ->  Tid Scan on p1_c3 p1_4
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c4
+   ->  Tid Scan on p1_c4 p1_5
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1_c1
+   ->  Tid Scan on p1_c1_c1 p1_6
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1_c2
+   ->  Tid Scan on p1_c1_c2 p1_7
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c3_c1
+   ->  Tid Scan on p1_c3_c1 p1_8
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c3_c2
+   ->  Tid Scan on p1_c3_c2 p1_9
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
 (28 rows)
@@ -3262,13 +3293,13 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (9 rows)
 
@@ -3281,19 +3312,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p1_pkey on p1
+   ->  Index Scan using p1_pkey on p1 p1_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_pkey on p1_c1
+   ->  Index Scan using p1_c1_pkey on p1_c1 p1_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1
+   ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1 p1_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2
+   ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2 p1_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -3310,22 +3341,22 @@ error hint:
                       QUERY PLAN                       
 -------------------------------------------------------
  Append
-   ->  Bitmap Heap Scan on p1
+   ->  Bitmap Heap Scan on p1 p1_1
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1
+   ->  Bitmap Heap Scan on p1_c1 p1_2
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1_c1
+   ->  Bitmap Heap Scan on p1_c1_c1 p1_3
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_c1_pkey
                Index Cond: ((id >= 50) AND (id <= 51))
-   ->  Bitmap Heap Scan on p1_c1_c2
+   ->  Bitmap Heap Scan on p1_c1_c2 p1_4
          Recheck Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
          ->  Bitmap Index Scan on p1_c1_c2_pkey
@@ -3344,16 +3375,16 @@ error hint:
                  QUERY PLAN                  
 ---------------------------------------------
  Append
-   ->  Tid Scan on p1
+   ->  Tid Scan on p1 p1_1
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1
+   ->  Tid Scan on p1_c1 p1_2
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1_c1
+   ->  Tid Scan on p1_c1_c1 p1_3
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
-   ->  Tid Scan on p1_c1_c2
+   ->  Tid Scan on p1_c1_c2 p1_4
          TID Cond: (ctid = '(1,1)'::tid)
          Filter: ((id >= 50) AND (id <= 51))
 (13 rows)
@@ -3367,23 +3398,23 @@ EXPLAIN (COSTS false) SELECT * FROM p1, t1 WHERE p1.id >= 50 AND p1.id <= 51 AND
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c2
+               ->  Seq Scan on p1_c2 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3
+               ->  Seq Scan on p1_c3 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c4
+               ->  Seq Scan on p1_c4 p1_5
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_6
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_7
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c1
+               ->  Seq Scan on p1_c3_c1 p1_8
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c2
+               ->  Seq Scan on p1_c3_c2 p1_9
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3398,13 +3429,13 @@ EXPLAIN (COSTS false) SELECT * FROM p1, t1 WHERE p1.id >= 50 AND p1.id <= 51 AND
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3427,23 +3458,23 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c2
+               ->  Seq Scan on p1_c2 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3
+               ->  Seq Scan on p1_c3 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c4
+               ->  Seq Scan on p1_c4 p1_5
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_6
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_7
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c1
+               ->  Seq Scan on p1_c3_c1 p1_8
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c2
+               ->  Seq Scan on p1_c3_c2 p1_9
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3458,37 +3489,37 @@ not used hint:
 duplication hint:
 error hint:
 
-                       QUERY PLAN                       
---------------------------------------------------------
+                         QUERY PLAN                          
+-------------------------------------------------------------
  Merge Join
    Merge Cond: (p1.id = t1.id)
    ->  Merge Append
          Sort Key: p1.id
-         ->  Index Scan using p1_pkey on p1
+         ->  Index Scan using p1_pkey on p1 p1_1
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_pkey on p1_c1
+         ->  Index Scan using p1_c1_pkey on p1_c1 p1_2
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c2_pkey on p1_c2
+         ->  Index Scan using p1_c2_pkey on p1_c2 p1_3
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c3_pkey on p1_c3
+         ->  Index Scan using p1_c3_pkey on p1_c3 p1_4
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c4_pkey on p1_c4
+         ->  Index Scan using p1_c4_pkey on p1_c4 p1_5
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1
+         ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1 p1_6
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2
+         ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2 p1_7
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c3_c1_pkey on p1_c3_c1
+         ->  Index Scan using p1_c3_c1_pkey on p1_c3_c1 p1_8
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c3_c2_pkey on p1_c3_c2
+         ->  Index Scan using p1_c3_c2_pkey on p1_c3_c2 p1_9
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
    ->  Index Scan using t1_pkey on t1
@@ -3511,47 +3542,47 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Bitmap Heap Scan on p1
+               ->  Bitmap Heap Scan on p1 p1_1
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1
+               ->  Bitmap Heap Scan on p1_c1 p1_2
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c2
+               ->  Bitmap Heap Scan on p1_c2 p1_3
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c2_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c3
+               ->  Bitmap Heap Scan on p1_c3 p1_4
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c3_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c4
+               ->  Bitmap Heap Scan on p1_c4 p1_5
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c4_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1_c1
+               ->  Bitmap Heap Scan on p1_c1_c1 p1_6
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_c1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1_c2
+               ->  Bitmap Heap Scan on p1_c1_c2 p1_7
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_c2_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c3_c1
+               ->  Bitmap Heap Scan on p1_c3_c1 p1_8
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c3_c1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c3_c2
+               ->  Bitmap Heap Scan on p1_c3_c2 p1_9
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c3_c2_pkey
@@ -3576,31 +3607,31 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Tid Scan on p1
+               ->  Tid Scan on p1 p1_1
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1
+               ->  Tid Scan on p1_c1 p1_2
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c2
+               ->  Tid Scan on p1_c2 p1_3
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c3
+               ->  Tid Scan on p1_c3 p1_4
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c4
+               ->  Tid Scan on p1_c4 p1_5
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1_c1
+               ->  Tid Scan on p1_c1_c1 p1_6
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1_c2
+               ->  Tid Scan on p1_c1_c2 p1_7
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c3_c1
+               ->  Tid Scan on p1_c3_c1 p1_8
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c3_c2
+               ->  Tid Scan on p1_c3_c2 p1_9
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
@@ -3616,32 +3647,32 @@ not used hint:
 duplication hint:
 error hint:
 
-                                    QUERY PLAN                                     
------------------------------------------------------------------------------------
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
+   ->  Append
+         ->  Seq Scan on p1 p1_1
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c1 p1_2
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c2 p1_3
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c3 p1_4
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c4 p1_5
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c1_c1 p1_6
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c1_c2 p1_7
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c3_c1 p1_8
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Seq Scan on p1_c3_c2 p1_9
+               Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Materialize
-         ->  Append
-               ->  Seq Scan on p1
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c2
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c4
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c1
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c2
-                     Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+         ->  Index Scan using t1_pkey on t1
+               Index Cond: (id < 10)
 (24 rows)
 
 /*+MergeJoin(p1 t1)*/
@@ -3660,23 +3691,23 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c2
+               ->  Seq Scan on p1_c2 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3
+               ->  Seq Scan on p1_c3 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c4
+               ->  Seq Scan on p1_c4 p1_5
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_6
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_7
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c1
+               ->  Seq Scan on p1_c3_c1 p1_8
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c3_c2
+               ->  Seq Scan on p1_c3_c2 p1_9
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3696,23 +3727,23 @@ error hint:
  Hash Join
    Hash Cond: (p1.id = t1.id)
    ->  Append
-         ->  Seq Scan on p1
+         ->  Seq Scan on p1 p1_1
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c1
+         ->  Seq Scan on p1_c1 p1_2
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c2
+         ->  Seq Scan on p1_c2 p1_3
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c3
+         ->  Seq Scan on p1_c3 p1_4
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c4
+         ->  Seq Scan on p1_c4 p1_5
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c1_c1
+         ->  Seq Scan on p1_c1_c1 p1_6
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c1_c2
+         ->  Seq Scan on p1_c1_c2 p1_7
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c3_c1
+         ->  Seq Scan on p1_c3_c1 p1_8
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-         ->  Seq Scan on p1_c3_c2
+         ->  Seq Scan on p1_c3_c2 p1_9
                Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Hash
          ->  Index Scan using t1_pkey on t1
@@ -3736,13 +3767,13 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3757,22 +3788,22 @@ not used hint:
 duplication hint:
 error hint:
 
-                       QUERY PLAN                       
---------------------------------------------------------
+                         QUERY PLAN                          
+-------------------------------------------------------------
  Merge Join
    Merge Cond: (p1.id = t1.id)
    ->  Merge Append
          Sort Key: p1.id
-         ->  Index Scan using p1_pkey on p1
+         ->  Index Scan using p1_pkey on p1 p1_1
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_pkey on p1_c1
+         ->  Index Scan using p1_c1_pkey on p1_c1 p1_2
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1
+         ->  Index Scan using p1_c1_c1_pkey on p1_c1_c1 p1_3
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
-         ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2
+         ->  Index Scan using p1_c1_c2_pkey on p1_c1_c2 p1_4
                Index Cond: ((id >= 50) AND (id <= 51))
                Filter: (ctid = '(1,1)'::tid)
    ->  Index Scan using t1_pkey on t1
@@ -3795,22 +3826,22 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Bitmap Heap Scan on p1
+               ->  Bitmap Heap Scan on p1 p1_1
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1
+               ->  Bitmap Heap Scan on p1_c1 p1_2
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1_c1
+               ->  Bitmap Heap Scan on p1_c1_c1 p1_3
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_c1_pkey
                            Index Cond: ((id >= 50) AND (id <= 51))
-               ->  Bitmap Heap Scan on p1_c1_c2
+               ->  Bitmap Heap Scan on p1_c1_c2 p1_4
                      Recheck Cond: ((id >= 50) AND (id <= 51))
                      Filter: (ctid = '(1,1)'::tid)
                      ->  Bitmap Index Scan on p1_c1_c2_pkey
@@ -3835,16 +3866,16 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Tid Scan on p1
+               ->  Tid Scan on p1 p1_1
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1
+               ->  Tid Scan on p1_c1 p1_2
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1_c1
+               ->  Tid Scan on p1_c1_c1 p1_3
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
-               ->  Tid Scan on p1_c1_c2
+               ->  Tid Scan on p1_c1_c2 p1_4
                      TID Cond: (ctid = '(1,1)'::tid)
                      Filter: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
@@ -3868,13 +3899,13 @@ error hint:
          Index Cond: (id < 10)
    ->  Materialize
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (14 rows)
 
@@ -3894,13 +3925,13 @@ error hint:
    ->  Sort
          Sort Key: p1.id
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
@@ -3923,13 +3954,13 @@ error hint:
          Index Cond: (id < 10)
    ->  Hash
          ->  Append
-               ->  Seq Scan on p1
+               ->  Seq Scan on p1 p1_1
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1
+               ->  Seq Scan on p1_c1 p1_2
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c1
+               ->  Seq Scan on p1_c1_c1 p1_3
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-               ->  Seq Scan on p1_c1_c2
+               ->  Seq Scan on p1_c1_c2 p1_4
                      Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (14 rows)
 
@@ -4028,10 +4059,10 @@ error hint:
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 /*+MergeJoin(p1 t1)*/
@@ -4154,10 +4185,10 @@ error hint:
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 /*+MergeJoin(p1 t1)*/
@@ -4207,10 +4238,10 @@ EXPLAIN (COSTS false) SELECT * FROM ONLY p1, t1 WHERE p1.id >= 50 AND p1.id <= 5
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 SET constraint_exclusion TO on;
@@ -4219,10 +4250,10 @@ EXPLAIN (COSTS false) SELECT * FROM ONLY p1, t1 WHERE p1.id >= 50 AND p1.id <= 5
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 SET constraint_exclusion TO off;
@@ -4239,10 +4270,10 @@ error hint:
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 /*+IndexScan(p1)*/
@@ -4274,19 +4305,18 @@ not used hint:
 duplication hint:
 error hint:
 
-                         QUERY PLAN                          
--------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
+   ->  Bitmap Heap Scan on p1
+         Recheck Cond: ((id >= 50) AND (id <= 51))
+         Filter: (ctid = '(1,1)'::tid)
+         ->  Bitmap Index Scan on p1_pkey
+               Index Cond: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
-   ->  Materialize
-         ->  Bitmap Heap Scan on p1
-               Recheck Cond: ((id >= 50) AND (id <= 51))
-               Filter: (ctid = '(1,1)'::tid)
-               ->  Bitmap Index Scan on p1_pkey
-                     Index Cond: ((id >= 50) AND (id <= 51))
-(10 rows)
+(9 rows)
 
 /*+TidScan(p1)*/
 EXPLAIN (COSTS false) SELECT * FROM ONLY p1, t1 WHERE p1.id >= 50 AND p1.id <= 51 AND p1.ctid = '(1,1)' AND p1.id = t1.id AND t1.id < 10;
@@ -4297,17 +4327,16 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                     
----------------------------------------------------
+                 QUERY PLAN                  
+---------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
+   ->  Tid Scan on p1
+         TID Cond: (ctid = '(1,1)'::tid)
+         Filter: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
-   ->  Materialize
-         ->  Tid Scan on p1
-               TID Cond: (ctid = '(1,1)'::tid)
-               Filter: ((id >= 50) AND (id <= 51))
-(8 rows)
+(7 rows)
 
 SET constraint_exclusion TO on;
 /*+SeqScan(p1)*/
@@ -4323,10 +4352,10 @@ error hint:
 -----------------------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
-   ->  Index Scan using t1_pkey on t1
-         Index Cond: (id < 10)
    ->  Seq Scan on p1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
+   ->  Index Scan using t1_pkey on t1
+         Index Cond: (id < 10)
 (6 rows)
 
 /*+IndexScan(p1)*/
@@ -4358,19 +4387,18 @@ not used hint:
 duplication hint:
 error hint:
 
-                         QUERY PLAN                          
--------------------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
+   ->  Bitmap Heap Scan on p1
+         Recheck Cond: ((id >= 50) AND (id <= 51))
+         Filter: (ctid = '(1,1)'::tid)
+         ->  Bitmap Index Scan on p1_pkey
+               Index Cond: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
-   ->  Materialize
-         ->  Bitmap Heap Scan on p1
-               Recheck Cond: ((id >= 50) AND (id <= 51))
-               Filter: (ctid = '(1,1)'::tid)
-               ->  Bitmap Index Scan on p1_pkey
-                     Index Cond: ((id >= 50) AND (id <= 51))
-(10 rows)
+(9 rows)
 
 /*+TidScan(p1)*/
 EXPLAIN (COSTS false) SELECT * FROM ONLY p1, t1 WHERE p1.id >= 50 AND p1.id <= 51 AND p1.ctid = '(1,1)' AND p1.id = t1.id AND t1.id < 10;
@@ -4381,17 +4409,16 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                     
----------------------------------------------------
+                 QUERY PLAN                  
+---------------------------------------------
  Nested Loop
    Join Filter: (p1.id = t1.id)
+   ->  Tid Scan on p1
+         TID Cond: (ctid = '(1,1)'::tid)
+         Filter: ((id >= 50) AND (id <= 51))
    ->  Index Scan using t1_pkey on t1
          Index Cond: (id < 10)
-   ->  Materialize
-         ->  Tid Scan on p1
-               TID Cond: (ctid = '(1,1)'::tid)
-               Filter: ((id >= 50) AND (id <= 51))
-(8 rows)
+(7 rows)
 
 -- quote test
 /*+SeqScan("""t1 )     ")IndexScan("t  2 """)HashJoin("""t1 )  "T3"t   2 """)Leading("""t1 )   "T3"t   2 """)Set(application_name"a    a       a""     a       A")*/
@@ -4496,18 +4523,7 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
                                   QUERY PLAN                                  
 ------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Merge Join
-                       Merge Cond: (t1_5.id = t2_5.id)
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $1)
+   InitPlan 1 (returns $0)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4518,7 +4534,7 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $2)
+   InitPlan 2 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -4535,20 +4551,29 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Index Only Scan using t1_pkey on t1 t1_1
-                                       Index Cond: (id = $2)
+                                       Index Cond: (id = $1)
                                  ->  Index Only Scan using t2_pkey on t2 t2_1
-                                       Index Cond: (id = $2)
+                                       Index Cond: (id = $1)
                            ->  Seq Scan on t3 t3_1
-                                 Filter: (id = $2)
+                                 Filter: (id = $1)
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                ->  Index Only Scan using t2_pkey on t2 t2_3
-                     Index Cond: (id = $2)
+                     Index Cond: (id = $1)
          ->  Seq Scan on t3 t3_3
-               Filter: (id = $2)
-   ->  CTE Scan on c1_1
-         Filter: (id = $2)
-(53 rows)
+               Filter: (id = $1)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $1)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Merge Join
+                     Merge Cond: (t1_5.id = t2_5.id)
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)*/
 EXPLAIN (COSTS false)
@@ -4576,18 +4601,7 @@ error hint:
                                   QUERY PLAN                                  
 ------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4598,7 +4612,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -4615,20 +4629,29 @@ error hint:
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Index Only Scan using t1_pkey on t1 t1_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                                  ->  Index Only Scan using t2_pkey on t2 t2_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                            ->  Seq Scan on t3 t3_1
-                                 Filter: (id = $5)
+                                 Filter: (id = $3)
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Index Only Scan using t2_pkey on t2 t2_3
-                     Index Cond: (id = $5)
+                     Index Cond: (id = $3)
          ->  Seq Scan on t3 t3_3
-               Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+               Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(a t1_1 t1_2 t1_4 t1_5)*/
 EXPLAIN (COSTS false)
@@ -4657,18 +4680,7 @@ error hint:
                                   QUERY PLAN                                  
 ------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4679,7 +4691,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -4696,20 +4708,29 @@ error hint:
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Index Only Scan using t1_pkey on t1 t1_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                                  ->  Index Only Scan using t2_pkey on t2 t2_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                            ->  Seq Scan on t3 t3_1
-                                 Filter: (id = $5)
+                                 Filter: (id = $3)
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Index Only Scan using t2_pkey on t2 t2_3
-                     Index Cond: (id = $5)
+                     Index Cond: (id = $3)
          ->  Seq Scan on t3 t3_3
-               Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+               Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(a t3_2 t3_5 t2_2 c1_1 t3_4 t3_3 t2_3 t2_4 t1_3 t2_5 t1_2 t3_1 t1_4 t2_1 t1_5 t1_1)*/
 EXPLAIN (COSTS false)
@@ -4738,18 +4759,7 @@ error hint:
                                   QUERY PLAN                                  
 ------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4760,7 +4770,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -4777,20 +4787,29 @@ error hint:
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Index Only Scan using t1_pkey on t1 t1_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                                  ->  Index Only Scan using t2_pkey on t2 t2_1
-                                       Index Cond: (id = $5)
+                                       Index Cond: (id = $3)
                            ->  Seq Scan on t3 t3_1
-                                 Filter: (id = $5)
+                                 Filter: (id = $3)
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Index Only Scan using t2_pkey on t2 t2_3
-                     Index Cond: (id = $5)
+                     Index Cond: (id = $3)
          ->  Seq Scan on t3 t3_3
-               Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+               Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(t3_5 t2_5 t1_5)Leading(t3_2 t2_2 t1_2)Leading(t3_4 t2_4 t1_4)Leading(c1_1 t3_3 t2_3 t1_3 t3_1 t2_1 t1_1)*/
 EXPLAIN (COSTS false)
@@ -4819,21 +4838,10 @@ NestLoop(t1_5 t2_5)
 duplication hint:
 error hint:
 
-                               QUERY PLAN                               
-------------------------------------------------------------------------
+                                           QUERY PLAN                                           
+------------------------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t2_5.id = t1_5.id)
-                 ->  Merge Join
-                       Merge Cond: (t2_5.id = t3_5.id)
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Sort
-                             Sort Key: t3_5.id
-                             ->  Seq Scan on t3 t3_5
-                 ->  Index Only Scan using t1_pkey on t1 t1_5
-   InitPlan 2 (returns $1)
+   InitPlan 1 (returns $0)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t2_2.id = t1_2.id)
@@ -4844,7 +4852,7 @@ error hint:
                              Sort Key: t3_2.id
                              ->  Seq Scan on t3 t3_2
                  ->  Index Only Scan using t1_pkey on t1 t1_2
-   InitPlan 3 (returns $2)
+   InitPlan 2 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t2_4.id = t1_4.id)
@@ -4861,20 +4869,29 @@ error hint:
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Seq Scan on t3 t3_3
-                                       Filter: (id = $2)
-                                 ->  CTE Scan on c1_1
-                                       Filter: (id = $2)
+                                       Filter: (id = $1)
+                                 ->  Aggregate
+                                       Filter: (max(t1_5.id) = $1)
+                                       ->  Merge Join
+                                             Merge Cond: (t2_5.id = t1_5.id)
+                                             ->  Merge Join
+                                                   Merge Cond: (t2_5.id = t3_5.id)
+                                                   ->  Index Only Scan using t2_pkey on t2 t2_5
+                                                   ->  Sort
+                                                         Sort Key: t3_5.id
+                                                         ->  Seq Scan on t3 t3_5
+                                             ->  Index Only Scan using t1_pkey on t1 t1_5
                            ->  Index Only Scan using t2_pkey on t2 t2_3
-                                 Index Cond: (id = $2)
+                                 Index Cond: (id = $1)
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $2)
+                     Filter: (id = $1)
          ->  Index Only Scan using t2_pkey on t2 t2_1
-               Index Cond: (id = $2)
+               Index Cond: (id = $1)
    ->  Index Only Scan using t1_pkey on t1 t1_1
-         Index Cond: (id = $2)
-(53 rows)
+         Index Cond: (id = $1)
+(51 rows)
 
 SET from_collapse_limit TO 1;
 EXPLAIN (COSTS false)
@@ -4891,18 +4908,7 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
                              QUERY PLAN                             
 --------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Merge Join
-                       Merge Cond: (t1_5.id = t2_5.id)
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $1)
+   InitPlan 1 (returns $0)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4913,7 +4919,7 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $2)
+   InitPlan 2 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -4928,22 +4934,31 @@ SELECT max(t1_4.id) FROM t1 t1_4, t2 t2_4, t3 t3_4 WHERE t1_4.id = t2_4.id AND t
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_1
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                      ->  Index Only Scan using t2_pkey on t2 t2_1
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $2)
+                     Filter: (id = $1)
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                      ->  Index Only Scan using t2_pkey on t2 t2_3
-                           Index Cond: (id = $2)
+                           Index Cond: (id = $1)
                ->  Seq Scan on t3 t3_3
-                     Filter: (id = $2)
-   ->  CTE Scan on c1_1
-         Filter: (id = $2)
-(53 rows)
+                     Filter: (id = $1)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $1)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Merge Join
+                     Merge Cond: (t1_5.id = t2_5.id)
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)*/
 EXPLAIN (COSTS false)
@@ -4971,18 +4986,7 @@ error hint:
                              QUERY PLAN                             
 --------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -4993,7 +4997,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -5008,22 +5012,31 @@ error hint:
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $5)
+                     Filter: (id = $3)
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_3
-                     Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+                     Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(a t1_1 t1_2 t1_4 t1_5)*/
 EXPLAIN (COSTS false)
@@ -5052,18 +5065,7 @@ error hint:
                              QUERY PLAN                             
 --------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -5074,7 +5076,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -5089,22 +5091,31 @@ error hint:
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $5)
+                     Filter: (id = $3)
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_3
-                     Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+                     Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(a t3_2 t3_5 t2_2 c1_1 t3_4 t3_3 t2_3 t2_4 t1_3 t2_5 t1_2 t3_1 t1_4 t2_1 t1_5 t1_1)*/
 EXPLAIN (COSTS false)
@@ -5133,18 +5144,7 @@ error hint:
                              QUERY PLAN                             
 --------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t1_5.id = t3_5.id)
-                 ->  Nested Loop
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Index Only Scan using t1_pkey on t1 t1_5
-                             Index Cond: (id = t2_5.id)
-                 ->  Sort
-                       Sort Key: t3_5.id
-                       ->  Seq Scan on t3 t3_5
-   InitPlan 2 (returns $3)
+   InitPlan 1 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_2.id = t3_2.id)
@@ -5155,7 +5155,7 @@ error hint:
                  ->  Sort
                        Sort Key: t3_2.id
                        ->  Seq Scan on t3 t3_2
-   InitPlan 3 (returns $5)
+   InitPlan 2 (returns $3)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t1_4.id = t3_4.id)
@@ -5170,22 +5170,31 @@ error hint:
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_1
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $5)
+                     Filter: (id = $3)
          ->  Nested Loop
                ->  Nested Loop
                      ->  Index Only Scan using t1_pkey on t1 t1_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                      ->  Index Only Scan using t2_pkey on t2 t2_3
-                           Index Cond: (id = $5)
+                           Index Cond: (id = $3)
                ->  Seq Scan on t3 t3_3
-                     Filter: (id = $5)
-   ->  CTE Scan on c1_1
-         Filter: (id = $5)
-(53 rows)
+                     Filter: (id = $3)
+   ->  Aggregate
+         Filter: (max(t1_5.id) = $3)
+         ->  Merge Join
+               Merge Cond: (t1_5.id = t3_5.id)
+               ->  Nested Loop
+                     ->  Index Only Scan using t2_pkey on t2 t2_5
+                     ->  Index Only Scan using t1_pkey on t1 t1_5
+                           Index Cond: (id = t2_5.id)
+               ->  Sort
+                     Sort Key: t3_5.id
+                     ->  Seq Scan on t3 t3_5
+(51 rows)
 
 /*+HashJoin(t1_1 t3_1)MergeJoin(t1_3 t3_3)NestLoop(t1_2 t2_2)NestLoop(t1_4 t2_4)NestLoop(t1_5 t2_5)Leading(t3_5 t2_5 t1_5)Leading(t3_2 t2_2 t1_2)Leading(t3_4 t2_4 t1_4)Leading(c1_1 t3_3 t2_3 t1_3 t3_1 t2_1 t1_1)*/
 EXPLAIN (COSTS false)
@@ -5214,21 +5223,10 @@ NestLoop(t1_5 t2_5)
 duplication hint:
 error hint:
 
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
+                                     QUERY PLAN                                     
+------------------------------------------------------------------------------------
  Nested Loop
-   CTE c1_1
-     ->  Aggregate
-           ->  Merge Join
-                 Merge Cond: (t2_5.id = t1_5.id)
-                 ->  Merge Join
-                       Merge Cond: (t2_5.id = t3_5.id)
-                       ->  Index Only Scan using t2_pkey on t2 t2_5
-                       ->  Sort
-                             Sort Key: t3_5.id
-                             ->  Seq Scan on t3 t3_5
-                 ->  Index Only Scan using t1_pkey on t1 t1_5
-   InitPlan 2 (returns $1)
+   InitPlan 1 (returns $0)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t2_2.id = t1_2.id)
@@ -5239,7 +5237,7 @@ error hint:
                              Sort Key: t3_2.id
                              ->  Seq Scan on t3 t3_2
                  ->  Index Only Scan using t1_pkey on t1 t1_2
-   InitPlan 3 (returns $2)
+   InitPlan 2 (returns $1)
      ->  Aggregate
            ->  Merge Join
                  Merge Cond: (t2_4.id = t1_4.id)
@@ -5256,54 +5254,63 @@ error hint:
                      ->  Nested Loop
                            ->  Nested Loop
                                  ->  Index Only Scan using t1_pkey on t1 t1_3
-                                       Index Cond: (id = $2)
+                                       Index Cond: (id = $1)
                                  ->  Index Only Scan using t2_pkey on t2 t2_3
-                                       Index Cond: (id = $2)
+                                       Index Cond: (id = $1)
                            ->  Seq Scan on t3 t3_3
-                                 Filter: (id = $2)
-                     ->  CTE Scan on c1_1
-                           Filter: (id = $2)
+                                 Filter: (id = $1)
+                     ->  Aggregate
+                           Filter: (max(t1_5.id) = $1)
+                           ->  Merge Join
+                                 Merge Cond: (t2_5.id = t1_5.id)
+                                 ->  Merge Join
+                                       Merge Cond: (t2_5.id = t3_5.id)
+                                       ->  Index Only Scan using t2_pkey on t2 t2_5
+                                       ->  Sort
+                                             Sort Key: t3_5.id
+                                             ->  Seq Scan on t3 t3_5
+                                 ->  Index Only Scan using t1_pkey on t1 t1_5
                ->  Seq Scan on t3 t3_1
-                     Filter: (id = $2)
+                     Filter: (id = $1)
          ->  Index Only Scan using t2_pkey on t2 t2_1
-               Index Cond: (id = $2)
+               Index Cond: (id = $1)
    ->  Index Only Scan using t1_pkey on t1 t1_1
-         Index Cond: (id = $2)
-(53 rows)
+         Index Cond: (id = $1)
+(51 rows)
 
--- ambigous error
+-- ambiguous error
 EXPLAIN (COSTS false) SELECT * FROM t1, s0.t1, t2 WHERE public.t1.id = s0.t1.id AND public.t1.id = t2.id;
-                   QUERY PLAN                    
--------------------------------------------------
- Merge Join
-   Merge Cond: (t1.id = t2.id)
-   ->  Merge Join
-         Merge Cond: (t1.id = t1_1.id)
+                 QUERY PLAN                 
+--------------------------------------------
+ Nested Loop
+   ->  Nested Loop
+         ->  Seq Scan on t1 t1_1
          ->  Index Scan using t1_pkey on t1
-         ->  Index Scan using t1_pkey on t1 t1_1
+               Index Cond: (id = t1_1.id)
    ->  Index Scan using t2_pkey on t2
+         Index Cond: (id = t1.id)
 (7 rows)
 
-/*+NestLoop(t1 t2)*/
+/*+MergeJoin(t1 t2)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, s0.t1, t2 WHERE public.t1.id = s0.t1.id AND public.t1.id = t2.id;
-INFO:  pg_hint_plan: hint syntax error at or near "NestLoop(t1 t2)"
+INFO:  pg_hint_plan: hint syntax error at or near "MergeJoin(t1 t2)"
 DETAIL:  Relation name "t1" is ambiguous.
 LOG:  pg_hint_plan:
 used hint:
 not used hint:
 duplication hint:
 error hint:
-NestLoop(t1 t2)
+MergeJoin(t1 t2)
 
-                   QUERY PLAN                    
--------------------------------------------------
- Merge Join
-   Merge Cond: (t1.id = t2.id)
-   ->  Merge Join
-         Merge Cond: (t1.id = t1_1.id)
+                 QUERY PLAN                 
+--------------------------------------------
+ Nested Loop
+   ->  Nested Loop
+         ->  Seq Scan on t1 t1_1
          ->  Index Scan using t1_pkey on t1
-         ->  Index Scan using t1_pkey on t1 t1_1
+               Index Cond: (id = t1_1.id)
    ->  Index Scan using t2_pkey on t2
+         Index Cond: (id = t1.id)
 (7 rows)
 
 /*+Leading(t1 t2 t1)*/
@@ -5317,15 +5324,15 @@ duplication hint:
 error hint:
 Leading(t1 t2 t1)
 
-                   QUERY PLAN                    
--------------------------------------------------
- Merge Join
-   Merge Cond: (t1.id = t2.id)
-   ->  Merge Join
-         Merge Cond: (t1.id = t1_1.id)
+                 QUERY PLAN                 
+--------------------------------------------
+ Nested Loop
+   ->  Nested Loop
+         ->  Seq Scan on t1 t1_1
          ->  Index Scan using t1_pkey on t1
-         ->  Index Scan using t1_pkey on t1 t1_1
+               Index Cond: (id = t1_1.id)
    ->  Index Scan using t2_pkey on t2
+         Index Cond: (id = t1.id)
 (7 rows)
 
 -- identifier length test
@@ -5428,7 +5435,7 @@ ERROR:  1.23457e+63 is outside the valid range for parameter "cursor_tuple_fract
 /*+ Set(enable_seqscan 100)Set(seq_page_cost on)*/
 EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
 INFO:  parameter "enable_seqscan" requires a Boolean value
-INFO:  parameter "seq_page_cost" requires a numeric value
+INFO:  invalid value for parameter "seq_page_cost": "on"
 LOG:  pg_hint_plan:
 used hint:
 not used hint:
@@ -6086,6 +6093,7 @@ error hint:
                     QUERY PLAN                    
 --------------------------------------------------
  Nested Loop
+   Join Filter: (t3.id = t4.id)
    ->  Nested Loop
          Join Filter: (t1.val = t3.val)
          ->  Hash Join
@@ -6095,8 +6103,7 @@ error hint:
                ->  Hash
                      ->  Seq Scan on t2
          ->  Seq Scan on t3
-   ->  Index Scan using t4_pkey on t4
-         Index Cond: (id = t3.id)
+   ->  Seq Scan on t4
 (12 rows)
 
 /*+Leading(((t1 t2) t3)) MergeJoin(t1 t2 t3 t4)*/
@@ -6510,13 +6517,13 @@ EXPLAIN (COSTS false) SELECT * FROM p2 WHERE id >= 50 AND id <= 51 AND p2.ctid =
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (9 rows)
 
@@ -6533,19 +6540,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_pkey on p2_c1
+   ->  Index Scan using p2_c1_pkey on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6563,19 +6570,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                       QUERY PLAN                       
---------------------------------------------------------
+                         QUERY PLAN                          
+-------------------------------------------------------------
  Append
-   ->  Index Scan using p2_id_val_idx on p2
+   ->  Index Scan using p2_id_val_idx on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_id_val_idx on p2_c1
+   ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_id_val_idx on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_id_val_idx on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_id_val_idx on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_id_val_idx on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6593,19 +6600,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                       QUERY PLAN                       
---------------------------------------------------------
+                         QUERY PLAN                          
+-------------------------------------------------------------
  Append
-   ->  Index Scan using p2_val_id_idx on p2
+   ->  Index Scan using p2_val_id_idx on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_val_id_idx on p2_c1
+   ->  Index Scan using p2_c1_val_id_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_val_id_idx on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_val_id_idx on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_val_id_idx on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_val_id_idx on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6614,23 +6621,23 @@ EXPLAIN (COSTS false) SELECT val FROM p2 WHERE val >= '50' AND val <= '51' AND p
                                        QUERY PLAN                                        
 -----------------------------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c2
+   ->  Seq Scan on p2_c2 p2_3
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3
+   ->  Seq Scan on p2_c3 p2_4
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c4
+   ->  Seq Scan on p2_c4 p2_5
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_6
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_7
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c1
+   ->  Seq Scan on p2_c3_c1 p2_8
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c2
+   ->  Seq Scan on p2_c3_c2 p2_9
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
@@ -6657,23 +6664,23 @@ error hint:
                                        QUERY PLAN                                        
 -----------------------------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c2
+   ->  Seq Scan on p2_c2 p2_3
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3
+   ->  Seq Scan on p2_c3 p2_4
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c4
+   ->  Seq Scan on p2_c4 p2_5
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_6
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_7
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c1
+   ->  Seq Scan on p2_c3_c1 p2_8
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c2
+   ->  Seq Scan on p2_c3_c2 p2_9
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
@@ -6690,19 +6697,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_pkey on p2_c1
+   ->  Index Scan using p2_c1_pkey on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6723,15 +6730,15 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Index Scan using p2_id2_val on p2
+   ->  Index Scan using p2_id2_val on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_id2_val on p2_c1
+   ->  Index Scan using p2_c1_id2_val on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (11 rows)
 
@@ -6751,14 +6758,14 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Index Scan using p2_val2_id on p2
+   ->  Index Scan using p2_val2_id on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (10 rows)
 
@@ -6775,19 +6782,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_pkey on p2_c1
+   ->  Index Scan using p2_c1_pkey on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6808,14 +6815,14 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Index Scan using p2_c1_id_val_idx on p2_c1
+   ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (10 rows)
 
@@ -6835,13 +6842,13 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (9 rows)
 
@@ -6858,19 +6865,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_id_val_idx on p2_c1
+   ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6888,19 +6895,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_pkey on p2_c1
+   ->  Index Scan using p2_c1_pkey on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6921,14 +6928,14 @@ error hint:
                               QUERY PLAN                               
 -----------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Index Scan using p2_c1_id_val_idx on p2_c1
+   ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_3
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_4
          Filter: ((id >= 50) AND (id <= 51) AND (ctid = '(1,1)'::tid))
 (10 rows)
 
@@ -6945,19 +6952,19 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p2_pkey on p2
+   ->  Index Scan using p2_pkey on p2 p2_1
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_id_val_idx on p2_c1
+   ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_pkey on p2_c1_c1 p2_3
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_pkey on p2_c1_c2 p2_4
          Index Cond: ((id >= 50) AND (id <= 51))
          Filter: (ctid = '(1,1)'::tid)
 (13 rows)
@@ -6983,31 +6990,31 @@ error hint:
                             QUERY PLAN                             
 -------------------------------------------------------------------
  Append
-   ->  Index Scan using p2_val_idx on p2
+   ->  Index Scan using p2_val_idx on p2 p2_1
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_val_idx on p2_c1
+   ->  Index Scan using p2_c1_val_idx on p2_c1 p2_2
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c2_val_idx on p2_c2
+   ->  Index Scan using p2_c2_val_idx on p2_c2 p2_3
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_val_idx on p2_c3
+   ->  Index Scan using p2_c3_val_idx on p2_c3 p2_4
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c4_val_idx on p2_c4
+   ->  Index Scan using p2_c4_val_idx on p2_c4 p2_5
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_val_idx on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_val_idx on p2_c1_c1 p2_6
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_val_idx on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_val_idx on p2_c1_c2 p2_7
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_c1_val_idx on p2_c3_c1
+   ->  Index Scan using p2_c3_c1_val_idx on p2_c3_c1 p2_8
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_c2_val_idx on p2_c3_c2
+   ->  Index Scan using p2_c3_c2_val_idx on p2_c3_c2 p2_9
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
 (28 rows)
@@ -7033,37 +7040,37 @@ error hint:
                                        QUERY PLAN                                        
 -----------------------------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c2
+   ->  Seq Scan on p2_c2 p2_3
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3
+   ->  Seq Scan on p2_c3 p2_4
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c4
+   ->  Seq Scan on p2_c4 p2_5
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_6
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_7
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c1
+   ->  Seq Scan on p2_c3_c1 p2_8
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c2
+   ->  Seq Scan on p2_c3_c2 p2_9
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
 /*+IndexScan(p2 p2_val_idx6)*/
 EXPLAIN (COSTS false) SELECT val FROM p2 WHERE val >= '50' AND val <= '51' AND p2.ctid = '(1,1)';
 LOG:  available indexes for IndexScan(p2): p2_val_idx6
-LOG:  available indexes for IndexScan(p2_c1): p2_c1_val_idx6
-LOG:  available indexes for IndexScan(p2_c2): p2_c2_val_idx6
-LOG:  available indexes for IndexScan(p2_c3): p2_c3_val_idx6
-LOG:  available indexes for IndexScan(p2_c4): p2_c4_val_idx6
-LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_val_idx6
-LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_val_idx6
-LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_val_idx6
-LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_val_idx6
+LOG:  available indexes for IndexScan(p2_c1): p2_c1_val_idx7
+LOG:  available indexes for IndexScan(p2_c2): p2_c2_val_idx7
+LOG:  available indexes for IndexScan(p2_c3): p2_c3_val_idx7
+LOG:  available indexes for IndexScan(p2_c4): p2_c4_val_idx7
+LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_val_idx7
+LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_val_idx7
+LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_val_idx7
+LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_val_idx7
 LOG:  pg_hint_plan:
 used hint:
 IndexScan(p2 p2_val_idx6)
@@ -7074,37 +7081,37 @@ error hint:
                                        QUERY PLAN                                        
 -----------------------------------------------------------------------------------------
  Append
-   ->  Seq Scan on p2
+   ->  Seq Scan on p2 p2_1
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1
+   ->  Seq Scan on p2_c1 p2_2
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c2
+   ->  Seq Scan on p2_c2 p2_3
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3
+   ->  Seq Scan on p2_c3 p2_4
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c4
+   ->  Seq Scan on p2_c4 p2_5
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c1
+   ->  Seq Scan on p2_c1_c1 p2_6
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c1_c2
+   ->  Seq Scan on p2_c1_c2 p2_7
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c1
+   ->  Seq Scan on p2_c3_c1 p2_8
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
-   ->  Seq Scan on p2_c3_c2
+   ->  Seq Scan on p2_c3_c2 p2_9
          Filter: ((val >= '50'::text) AND (val <= '51'::text) AND (ctid = '(1,1)'::tid))
 (19 rows)
 
 /*+IndexScan(p2 p2_val_idx p2_val_idx6)*/
 EXPLAIN (COSTS false) SELECT val FROM p2 WHERE val >= '50' AND val <= '51' AND p2.ctid = '(1,1)';
 LOG:  available indexes for IndexScan(p2): p2_val_idx6 p2_val_idx
-LOG:  available indexes for IndexScan(p2_c1): p2_c1_val_idx6 p2_c1_val_idx
-LOG:  available indexes for IndexScan(p2_c2): p2_c2_val_idx6 p2_c2_val_idx
-LOG:  available indexes for IndexScan(p2_c3): p2_c3_val_idx6 p2_c3_val_idx
-LOG:  available indexes for IndexScan(p2_c4): p2_c4_val_idx6 p2_c4_val_idx
-LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_val_idx6 p2_c1_c1_val_idx
-LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_val_idx6 p2_c1_c2_val_idx
-LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_val_idx6 p2_c3_c1_val_idx
-LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_val_idx6 p2_c3_c2_val_idx
+LOG:  available indexes for IndexScan(p2_c1): p2_c1_val_idx7 p2_c1_val_idx
+LOG:  available indexes for IndexScan(p2_c2): p2_c2_val_idx7 p2_c2_val_idx
+LOG:  available indexes for IndexScan(p2_c3): p2_c3_val_idx7 p2_c3_val_idx
+LOG:  available indexes for IndexScan(p2_c4): p2_c4_val_idx7 p2_c4_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_val_idx7 p2_c1_c1_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_val_idx7 p2_c1_c2_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_val_idx7 p2_c3_c1_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_val_idx7 p2_c3_c2_val_idx
 LOG:  pg_hint_plan:
 used hint:
 IndexScan(p2 p2_val_idx p2_val_idx6)
@@ -7115,31 +7122,31 @@ error hint:
                             QUERY PLAN                             
 -------------------------------------------------------------------
  Append
-   ->  Index Scan using p2_val_idx on p2
+   ->  Index Scan using p2_val_idx on p2 p2_1
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_val_idx on p2_c1
+   ->  Index Scan using p2_c1_val_idx on p2_c1 p2_2
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c2_val_idx on p2_c2
+   ->  Index Scan using p2_c2_val_idx on p2_c2 p2_3
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_val_idx on p2_c3
+   ->  Index Scan using p2_c3_val_idx on p2_c3 p2_4
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c4_val_idx on p2_c4
+   ->  Index Scan using p2_c4_val_idx on p2_c4 p2_5
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c1_val_idx on p2_c1_c1
+   ->  Index Scan using p2_c1_c1_val_idx on p2_c1_c1 p2_6
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c1_c2_val_idx on p2_c1_c2
+   ->  Index Scan using p2_c1_c2_val_idx on p2_c1_c2 p2_7
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_c1_val_idx on p2_c3_c1
+   ->  Index Scan using p2_c3_c1_val_idx on p2_c3_c1 p2_8
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
-   ->  Index Scan using p2_c3_c2_val_idx on p2_c3_c2
+   ->  Index Scan using p2_c3_c2_val_idx on p2_c3_c2 p2_9
          Index Cond: ((val >= '50'::text) AND (val <= '51'::text))
          Filter: (ctid = '(1,1)'::tid)
 (28 rows)
@@ -7399,26 +7406,26 @@ error hint:
 
 -- Inheritance
 EXPLAIN (COSTS false) SELECT val FROM p1 WHERE val = 1;
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7440,26 +7447,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7481,26 +7488,26 @@ not used hint:
 duplication hint:
 error hint:
 
-                    QUERY PLAN                    
---------------------------------------------------
+                      QUERY PLAN                       
+-------------------------------------------------------
  Append
-   ->  Index Scan using p1_val2 on p1
+   ->  Index Scan using p1_val2 on p1 p1_1
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c1_val2 on p1_c1
+   ->  Index Scan using p1_c1_val2 on p1_c1 p1_2
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c2_val2 on p1_c2
+   ->  Index Scan using p1_c2_val2 on p1_c2 p1_3
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c3_val2 on p1_c3
+   ->  Index Scan using p1_c3_val2 on p1_c3 p1_4
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c4_val2 on p1_c4
+   ->  Index Scan using p1_c4_val2 on p1_c4 p1_5
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c1_c1_val2 on p1_c1_c1
+   ->  Index Scan using p1_c1_c1_val2 on p1_c1_c1 p1_6
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c1_c2_val2 on p1_c1_c2
+   ->  Index Scan using p1_c1_c2_val2 on p1_c1_c2 p1_7
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c3_c1_val2 on p1_c3_c1
+   ->  Index Scan using p1_c3_c1_val2 on p1_c3_c1 p1_8
          Index Cond: (val = 1)
-   ->  Index Scan using p1_c3_c2_val2 on p1_c3_c2
+   ->  Index Scan using p1_c3_c2_val2 on p1_c3_c2 p1_9
          Index Cond: (val = 1)
 (19 rows)
 
@@ -7522,26 +7529,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7563,26 +7570,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7604,26 +7611,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7645,26 +7652,26 @@ not used hint:
 duplication hint:
 error hint:
 
-                      QUERY PLAN                       
--------------------------------------------------------
+                         QUERY PLAN                         
+------------------------------------------------------------
  Append
-   ->  Index Only Scan using p1_val2 on p1
+   ->  Index Only Scan using p1_val2 on p1 p1_1
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c1_val2 on p1_c1
+   ->  Index Only Scan using p1_c1_val2 on p1_c1 p1_2
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c2_val2 on p1_c2
+   ->  Index Only Scan using p1_c2_val2 on p1_c2 p1_3
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c3_val2 on p1_c3
+   ->  Index Only Scan using p1_c3_val2 on p1_c3 p1_4
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c4_val2 on p1_c4
+   ->  Index Only Scan using p1_c4_val2 on p1_c4 p1_5
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c1_c1_val2 on p1_c1_c1
+   ->  Index Only Scan using p1_c1_c1_val2 on p1_c1_c1 p1_6
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c1_c2_val2 on p1_c1_c2
+   ->  Index Only Scan using p1_c1_c2_val2 on p1_c1_c2 p1_7
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c3_c1_val2 on p1_c3_c1
+   ->  Index Only Scan using p1_c3_c1_val2 on p1_c3_c1 p1_8
          Index Cond: (val = 1)
-   ->  Index Only Scan using p1_c3_c2_val2 on p1_c3_c2
+   ->  Index Only Scan using p1_c3_c2_val2 on p1_c3_c2 p1_9
          Index Cond: (val = 1)
 (19 rows)
 
@@ -7686,26 +7693,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7727,26 +7734,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7768,26 +7775,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7812,39 +7819,39 @@ error hint:
                    QUERY PLAN                   
 ------------------------------------------------
  Append
-   ->  Bitmap Heap Scan on p1
+   ->  Bitmap Heap Scan on p1 p1_1
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c1
+   ->  Bitmap Heap Scan on p1_c1 p1_2
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c1_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c2
+   ->  Bitmap Heap Scan on p1_c2 p1_3
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c2_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c3
+   ->  Bitmap Heap Scan on p1_c3 p1_4
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c3_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c4
+   ->  Bitmap Heap Scan on p1_c4 p1_5
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c4_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c1_c1
+   ->  Bitmap Heap Scan on p1_c1_c1 p1_6
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c1_c1_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c1_c2
+   ->  Bitmap Heap Scan on p1_c1_c2 p1_7
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c1_c2_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c3_c1
+   ->  Bitmap Heap Scan on p1_c3_c1 p1_8
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c3_c1_val2
                Index Cond: (val = 1)
-   ->  Bitmap Heap Scan on p1_c3_c2
+   ->  Bitmap Heap Scan on p1_c3_c2 p1_9
          Recheck Cond: (val = 1)
          ->  Bitmap Index Scan on p1_c3_c2_val2
                Index Cond: (val = 1)
@@ -7868,26 +7875,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -7909,26 +7916,26 @@ not used hint:
 duplication hint:
 error hint:
 
-         QUERY PLAN         
-----------------------------
+           QUERY PLAN            
+---------------------------------
  Append
-   ->  Seq Scan on p1
+   ->  Seq Scan on p1 p1_1
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1
+   ->  Seq Scan on p1_c1 p1_2
          Filter: (val = 1)
-   ->  Seq Scan on p1_c2
+   ->  Seq Scan on p1_c2 p1_3
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3
+   ->  Seq Scan on p1_c3 p1_4
          Filter: (val = 1)
-   ->  Seq Scan on p1_c4
+   ->  Seq Scan on p1_c4 p1_5
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c1
+   ->  Seq Scan on p1_c1_c1 p1_6
          Filter: (val = 1)
-   ->  Seq Scan on p1_c1_c2
+   ->  Seq Scan on p1_c1_c2 p1_7
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c1
+   ->  Seq Scan on p1_c3_c1 p1_8
          Filter: (val = 1)
-   ->  Seq Scan on p1_c3_c2
+   ->  Seq Scan on p1_c3_c2 p1_9
          Filter: (val = 1)
 (19 rows)
 
@@ -8052,7 +8059,7 @@ not used hint:
 duplication hint:
 error hint:
 
-CONTEXT:  SQL statement "SELECT 1, /*+ SeqScan(t1) */ * from t1"
+CONTEXT:  SQL statement "SELECT  1, /*+ SeqScan(t1) */ * from t1"
 PL/pgSQL function testfunc() line 3 at PERFORM
  testfunc 
 ----------
@@ -8198,24 +8205,617 @@ error hint:
 
 DROP FUNCTION testfunc();
 DROP EXTENSION pg_hint_plan;
+CREATE FUNCTION reset_stats_and_wait() RETURNS void AS $$
+DECLARE
+  rows int;
+BEGIN
+  rows = 1;
+  while rows > 0 LOOP
+   PERFORM pg_stat_reset();
+   PERFORM pg_sleep(0.5);
+   SELECT sum(seq_scan + idx_scan) from pg_stat_user_tables into rows;
+  END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+-- Dynamic query in pl/pgsql
+CREATE OR REPLACE FUNCTION dynsql1(x int) RETURNS int AS $$
+DECLARE c int;
+BEGIN
+  EXECUTE '/*+ IndexScan(t1) */ SELECT count(*) FROM t1 WHERE id < $1'
+       INTO c USING x;
+  RETURN c;
+END;
+$$ VOLATILE LANGUAGE plpgsql;
+vacuum analyze t1;
+SET pg_hint_plan.enable_hint = false;
+SELECT pg_sleep(1);
+ pg_sleep 
+----------
+(1 row)
+
+SELECT reset_stats_and_wait();
+ reset_stats_and_wait 
+----------------------
+(1 row)
+
+SELECT dynsql1(9000);
+ dynsql1 
+---------
+    8999
+(1 row)
+
+SELECT pg_sleep(1);
+ pg_sleep 
+----------
+(1 row)
+
+SELECT relname, seq_scan > 0 as seq_scan, idx_scan > 0 as idx_scan FROM pg_stat_user_tables WHERE schemaname = 'public' AND relname = 't1';
+ relname | seq_scan | idx_scan 
+---------+----------+----------
+ t1      | t        | f
+(1 row)
+
+SET pg_hint_plan.enable_hint = true;
+SELECT reset_stats_and_wait();
+ reset_stats_and_wait 
+----------------------
+(1 row)
+
+SELECT dynsql1(9000);
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(t1)
+not used hint:
+duplication hint:
+error hint:
+
+CONTEXT:  SQL statement "/*+ IndexScan(t1) */ SELECT count(*) FROM t1 WHERE id < $1"
+PL/pgSQL function dynsql1(integer) line 4 at EXECUTE
+ dynsql1 
+---------
+    8999
+(1 row)
+
+SELECT pg_sleep(1);
+ pg_sleep 
+----------
+(1 row)
+
+SELECT relname, seq_scan > 0 as seq_scan, idx_scan > 0 as idx_scan FROM pg_stat_user_tables WHERE schemaname = 'public' AND relname = 't1';
+ relname | seq_scan | idx_scan 
+---------+----------+----------
+ t1      | f        | t
+(1 row)
+
+-- Looped dynamic query in pl/pgsql
+CREATE OR REPLACE FUNCTION dynsql2(x int, OUT r int) AS $$
+DECLARE
+  c text;
+  s int;
+BEGIN
+  r := 0;
+  FOR c IN SELECT f.f FROM (VALUES ('p1_c1'), ('p1_c2')) f(f) LOOP
+    FOR s IN EXECUTE '/*+ IndexScan(' || c || ' ' || c || '_pkey) */ SELECT sum(val) FROM ' || c || ' WHERE id < ' || x LOOP
+      r := r + s;
+    END LOOP;
+  END LOOP;
+END;
+$$ VOLATILE LANGUAGE plpgsql;
+SET pg_hint_plan.enable_hint = false;
+SELECT reset_stats_and_wait();
+ reset_stats_and_wait 
+----------------------
+(1 row)
+
+SELECT dynsql2(9000);
+ dynsql2 
+---------
+    9900
+(1 row)
+
+SELECT pg_sleep(1);
+ pg_sleep 
+----------
+(1 row)
+
+-- one of the index scans happened while planning.
+SELECT relname, seq_scan, idx_scan FROM pg_stat_user_tables WHERE schemaname = 'public' AND (relname = 'p1_c1' OR relname = 'p1_c2');
+ relname | seq_scan | idx_scan 
+---------+----------+----------
+ p1_c1   |        1 |        0
+ p1_c2   |        1 |        1
+(2 rows)
+
+SET pg_hint_plan.enable_hint = true;
+SELECT reset_stats_and_wait();
+ reset_stats_and_wait 
+----------------------
+(1 row)
+
+SELECT dynsql2(9000);
+LOG:  available indexes for IndexScan(p1_c1): p1_c1_pkey
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c1 p1_c1_pkey) */ SELECT sum(val) FROM p1_c1 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+LOG:  available indexes for IndexScan(p1_c1_c1): p1_c1_c1_pkey
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c1 p1_c1_pkey) */ SELECT sum(val) FROM p1_c1 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+LOG:  available indexes for IndexScan(p1_c1_c2): p1_c1_c2_pkey
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c1 p1_c1_pkey) */ SELECT sum(val) FROM p1_c1 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p1_c1 p1_c1_pkey)
+not used hint:
+duplication hint:
+error hint:
+
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c1 p1_c1_pkey) */ SELECT sum(val) FROM p1_c1 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+LOG:  available indexes for IndexScan(p1_c2): p1_c2_pkey
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c2 p1_c2_pkey) */ SELECT sum(val) FROM p1_c2 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p1_c2 p1_c2_pkey)
+not used hint:
+duplication hint:
+error hint:
+
+CONTEXT:  SQL statement "/*+ IndexScan(p1_c2 p1_c2_pkey) */ SELECT sum(val) FROM p1_c2 WHERE id < 9000"
+PL/pgSQL function dynsql2(integer) line 8 at FOR over EXECUTE statement
+ dynsql2 
+---------
+    9900
+(1 row)
+
+SELECT pg_sleep(1);
+ pg_sleep 
+----------
+(1 row)
+
+-- the index scan happened while planning.
+SELECT relname, seq_scan, idx_scan FROM pg_stat_user_tables WHERE schemaname = 'public' AND (relname = 'p1_c1' OR relname = 'p1_c2');
+ relname | seq_scan | idx_scan 
+---------+----------+----------
+ p1_c1   |        0 |        1
+ p1_c2   |        0 |        2
+(2 rows)
+
+-- Subqueries on inheritance tables under UNION
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION ALL
+SELECT val::int FROM p2 WHERE id < 1000;
+                 QUERY PLAN                  
+---------------------------------------------
+ Append
+   ->  Append
+         ->  Seq Scan on p1 p1_1
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c1 p1_2
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c2 p1_3
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c3 p1_4
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c4 p1_5
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c1_c1 p1_6
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c1_c2 p1_7
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c3_c1 p1_8
+               Filter: (val < 1000)
+         ->  Seq Scan on p1_c3_c2 p1_9
+               Filter: (val < 1000)
+   ->  Result
+         ->  Append
+               ->  Seq Scan on p2 p2_1
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1 p2_2
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c2 p2_3
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3 p2_4
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c4 p2_5
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1_c1 p2_6
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1_c2 p2_7
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3_c1 p2_8
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3_c2 p2_9
+                     Filter: (id < 1000)
+(40 rows)
+
+/*+ IndexScan(p1 p1_val2) */
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION ALL
+SELECT val::int FROM p2 WHERE id < 1000;
+LOG:  available indexes for IndexScan(p1): p1_val3 p1_val2 p1_val1
+LOG:  available indexes for IndexScan(p1_c1): p1_c1_val3 p1_c1_val2 p1_c1_val1
+LOG:  available indexes for IndexScan(p1_c2): p1_c2_val3 p1_c2_val2 p1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3): p1_c3_val3 p1_c3_val2 p1_c3_val1
+LOG:  available indexes for IndexScan(p1_c4): p1_c4_val3 p1_c4_val2 p1_c4_val1
+LOG:  available indexes for IndexScan(p1_c1_c1): p1_c1_c1_val3 p1_c1_c1_val2 p1_c1_c1_val1
+LOG:  available indexes for IndexScan(p1_c1_c2): p1_c1_c2_val3 p1_c1_c2_val2 p1_c1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3_c1): p1_c3_c1_val3 p1_c3_c1_val2 p1_c3_c1_val1
+LOG:  available indexes for IndexScan(p1_c3_c2): p1_c3_c2_val3 p1_c3_c2_val2 p1_c3_c2_val1
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p1 p1_val2)
+not used hint:
+duplication hint:
+error hint:
+
+                         QUERY PLAN                          
+-------------------------------------------------------------
+ Append
+   ->  Append
+         ->  Index Scan using p1_val3 on p1 p1_1
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_val3 on p1_c1 p1_2
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c2_val3 on p1_c2 p1_3
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_val3 on p1_c3 p1_4
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c4_val3 on p1_c4 p1_5
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_c1_val3 on p1_c1_c1 p1_6
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_c2_val3 on p1_c1_c2 p1_7
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_c1_val3 on p1_c3_c1 p1_8
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_c2_val3 on p1_c3_c2 p1_9
+               Index Cond: (val < 1000)
+   ->  Result
+         ->  Append
+               ->  Seq Scan on p2 p2_1
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1 p2_2
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c2 p2_3
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3 p2_4
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c4 p2_5
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1_c1 p2_6
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c1_c2 p2_7
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3_c1 p2_8
+                     Filter: (id < 1000)
+               ->  Seq Scan on p2_c3_c2 p2_9
+                     Filter: (id < 1000)
+(40 rows)
+
+/*+ IndexScan(p1 p1_val2) IndexScan(p2 p2_id_val_idx) */
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION ALL
+SELECT val::int FROM p2 WHERE id < 1000;
+LOG:  available indexes for IndexScan(p1): p1_val3 p1_val2 p1_val1
+LOG:  available indexes for IndexScan(p1_c1): p1_c1_val3 p1_c1_val2 p1_c1_val1
+LOG:  available indexes for IndexScan(p1_c2): p1_c2_val3 p1_c2_val2 p1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3): p1_c3_val3 p1_c3_val2 p1_c3_val1
+LOG:  available indexes for IndexScan(p1_c4): p1_c4_val3 p1_c4_val2 p1_c4_val1
+LOG:  available indexes for IndexScan(p1_c1_c1): p1_c1_c1_val3 p1_c1_c1_val2 p1_c1_c1_val1
+LOG:  available indexes for IndexScan(p1_c1_c2): p1_c1_c2_val3 p1_c1_c2_val2 p1_c1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3_c1): p1_c3_c1_val3 p1_c3_c1_val2 p1_c3_c1_val1
+LOG:  available indexes for IndexScan(p1_c3_c2): p1_c3_c2_val3 p1_c3_c2_val2 p1_c3_c2_val1
+LOG:  available indexes for IndexScan(p2): p2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1): p2_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c2): p2_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3): p2_c3_id_val_idx
+LOG:  available indexes for IndexScan(p2_c4): p2_c4_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_id_val_idx
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p1 p1_val2)
+IndexScan(p2 p2_id_val_idx)
+not used hint:
+duplication hint:
+error hint:
+
+                               QUERY PLAN                                
+-------------------------------------------------------------------------
+ Append
+   ->  Append
+         ->  Index Scan using p1_val3 on p1 p1_1
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_val3 on p1_c1 p1_2
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c2_val3 on p1_c2 p1_3
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_val3 on p1_c3 p1_4
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c4_val3 on p1_c4 p1_5
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_c1_val3 on p1_c1_c1 p1_6
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c1_c2_val3 on p1_c1_c2 p1_7
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_c1_val3 on p1_c3_c1 p1_8
+               Index Cond: (val < 1000)
+         ->  Index Scan using p1_c3_c2_val3 on p1_c3_c2 p1_9
+               Index Cond: (val < 1000)
+   ->  Result
+         ->  Append
+               ->  Index Scan using p2_id_val_idx on p2 p2_1
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c2_id_val_idx on p2_c2 p2_3
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c3_id_val_idx on p2_c3 p2_4
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c4_id_val_idx on p2_c4 p2_5
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c1_c1_id_val_idx on p2_c1_c1 p2_6
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c1_c2_id_val_idx on p2_c1_c2 p2_7
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c3_c1_id_val_idx on p2_c3_c1 p2_8
+                     Index Cond: (id < 1000)
+               ->  Index Scan using p2_c3_c2_id_val_idx on p2_c3_c2 p2_9
+                     Index Cond: (id < 1000)
+(40 rows)
+
+-- union all case
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION
+SELECT val::int FROM p2 WHERE id < 1000;
+                    QUERY PLAN                     
+---------------------------------------------------
+ HashAggregate
+   Group Key: p1.val
+   ->  Append
+         ->  Append
+               ->  Seq Scan on p1 p1_1
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1 p1_2
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c2 p1_3
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3 p1_4
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c4 p1_5
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1_c1 p1_6
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1_c2 p1_7
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3_c1 p1_8
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3_c2 p1_9
+                     Filter: (val < 1000)
+         ->  Result
+               ->  Append
+                     ->  Seq Scan on p2 p2_1
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c1 p2_2
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c2 p2_3
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c3 p2_4
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c4 p2_5
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c1_c1 p2_6
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c1_c2 p2_7
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c3_c1 p2_8
+                           Filter: (id < 1000)
+                     ->  Seq Scan on p2_c3_c2 p2_9
+                           Filter: (id < 1000)
+(42 rows)
+
+/*+ IndexScan(p2 p2_id_val_idx) */
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION
+SELECT val::int FROM p2 WHERE id < 1000;
+LOG:  available indexes for IndexScan(p2): p2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1): p2_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c2): p2_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3): p2_c3_id_val_idx
+LOG:  available indexes for IndexScan(p2_c4): p2_c4_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_id_val_idx
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p2 p2_id_val_idx)
+not used hint:
+duplication hint:
+error hint:
+
+                                  QUERY PLAN                                   
+-------------------------------------------------------------------------------
+ HashAggregate
+   Group Key: p1.val
+   ->  Append
+         ->  Append
+               ->  Seq Scan on p1 p1_1
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1 p1_2
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c2 p1_3
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3 p1_4
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c4 p1_5
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1_c1 p1_6
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c1_c2 p1_7
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3_c1 p1_8
+                     Filter: (val < 1000)
+               ->  Seq Scan on p1_c3_c2 p1_9
+                     Filter: (val < 1000)
+         ->  Result
+               ->  Append
+                     ->  Index Scan using p2_id_val_idx on p2 p2_1
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c2_id_val_idx on p2_c2 p2_3
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_id_val_idx on p2_c3 p2_4
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c4_id_val_idx on p2_c4 p2_5
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_c1_id_val_idx on p2_c1_c1 p2_6
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_c2_id_val_idx on p2_c1_c2 p2_7
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_c1_id_val_idx on p2_c3_c1 p2_8
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_c2_id_val_idx on p2_c3_c2 p2_9
+                           Index Cond: (id < 1000)
+(42 rows)
+
+/*+ IndexScan(p1 p1_val2) IndexScan(p2 p2_id_val_idx) */
+EXPLAIN (COSTS off) SELECT val FROM p1 WHERE val < 1000
+UNION
+SELECT val::int FROM p2 WHERE id < 1000;
+LOG:  available indexes for IndexScan(p1): p1_val3 p1_val2 p1_val1
+LOG:  available indexes for IndexScan(p1_c1): p1_c1_val3 p1_c1_val2 p1_c1_val1
+LOG:  available indexes for IndexScan(p1_c2): p1_c2_val3 p1_c2_val2 p1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3): p1_c3_val3 p1_c3_val2 p1_c3_val1
+LOG:  available indexes for IndexScan(p1_c4): p1_c4_val3 p1_c4_val2 p1_c4_val1
+LOG:  available indexes for IndexScan(p1_c1_c1): p1_c1_c1_val3 p1_c1_c1_val2 p1_c1_c1_val1
+LOG:  available indexes for IndexScan(p1_c1_c2): p1_c1_c2_val3 p1_c1_c2_val2 p1_c1_c2_val1
+LOG:  available indexes for IndexScan(p1_c3_c1): p1_c3_c1_val3 p1_c3_c1_val2 p1_c3_c1_val1
+LOG:  available indexes for IndexScan(p1_c3_c2): p1_c3_c2_val3 p1_c3_c2_val2 p1_c3_c2_val1
+LOG:  available indexes for IndexScan(p2): p2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1): p2_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c2): p2_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3): p2_c3_id_val_idx
+LOG:  available indexes for IndexScan(p2_c4): p2_c4_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c1): p2_c1_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c1_c2): p2_c1_c2_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c1): p2_c3_c1_id_val_idx
+LOG:  available indexes for IndexScan(p2_c3_c2): p2_c3_c2_id_val_idx
+LOG:  pg_hint_plan:
+used hint:
+IndexScan(p1 p1_val2)
+IndexScan(p2 p2_id_val_idx)
+not used hint:
+duplication hint:
+error hint:
+
+                                  QUERY PLAN                                   
+-------------------------------------------------------------------------------
+ HashAggregate
+   Group Key: p1.val
+   ->  Append
+         ->  Append
+               ->  Index Scan using p1_val3 on p1 p1_1
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c1_val3 on p1_c1 p1_2
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c2_val3 on p1_c2 p1_3
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c3_val3 on p1_c3 p1_4
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c4_val3 on p1_c4 p1_5
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c1_c1_val3 on p1_c1_c1 p1_6
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c1_c2_val3 on p1_c1_c2 p1_7
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c3_c1_val3 on p1_c3_c1 p1_8
+                     Index Cond: (val < 1000)
+               ->  Index Scan using p1_c3_c2_val3 on p1_c3_c2 p1_9
+                     Index Cond: (val < 1000)
+         ->  Result
+               ->  Append
+                     ->  Index Scan using p2_id_val_idx on p2 p2_1
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_id_val_idx on p2_c1 p2_2
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c2_id_val_idx on p2_c2 p2_3
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_id_val_idx on p2_c3 p2_4
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c4_id_val_idx on p2_c4 p2_5
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_c1_id_val_idx on p2_c1_c1 p2_6
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c1_c2_id_val_idx on p2_c1_c2 p2_7
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_c1_id_val_idx on p2_c3_c1 p2_8
+                           Index Cond: (id < 1000)
+                     ->  Index Scan using p2_c3_c2_id_val_idx on p2_c3_c2 p2_9
+                           Index Cond: (id < 1000)
+(42 rows)
+
 --
 -- Rows hint tests
 --
 -- Explain result includes "Planning time" if COSTS is enabled, but
 -- this test needs it enabled for get rows count. So do tests via psql
 -- and grep -v the mutable line.
+-- Parse error check
+/*+ Rows() */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near " "
+DETAIL:  Rows hint needs at least one relation followed by one correction term.
+LOG:  pg_hint_plan:
+used hint:
+not used hint:
+duplication hint:
+error hint:
+Rows()
+
+ ?column? 
+----------
+        1
+(1 row)
+
+/*+ Rows(x) */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near " "
+DETAIL:  Rows hint needs at least one relation followed by one correction term.
+LOG:  pg_hint_plan:
+used hint:
+not used hint:
+duplication hint:
+error hint:
+Rows()
+
+ ?column? 
+----------
+        1
+(1 row)
+
 -- value types
 \o results/pg_hint_plan.tmpout
 EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id);
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1000 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1000 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 #99) */
@@ -8229,13 +8829,12 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=99 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=99 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 +99) */
@@ -8249,13 +8848,12 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1099 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1099 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 -99) */
@@ -8269,13 +8867,12 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=901 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=901 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 *99) */
@@ -8289,13 +8886,12 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=99000 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=99000 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 *0.01) */
@@ -8309,13 +8905,12 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=10 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=10 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 #aa) */
@@ -8331,13 +8926,12 @@ Rows(t1 t2 #aa)
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1000 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1000 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 /99) */
@@ -8353,13 +8947,12 @@ Rows(t1 t2 /99)
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1000 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1000 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 -- round up to 1
 \o results/pg_hint_plan.tmpout
@@ -8375,31 +8968,29 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                  QUERY PLAN                                  
-------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1 width=xxx)
    Merge Cond: (t1.id = t2.id)
-   ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-   ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-(4 rows)
+   ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+   ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
 
 -- complex join tree
 \o results/pg_hint_plan.tmpout
 EXPLAIN SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON (t3.id = t2.id);
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                     QUERY PLAN                                     
-------------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=10 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=10 width=xxx)
    Merge Cond: (t1.id = t3.id)
-   ->  Merge Join  (cost=xxx rows=1000 width=xxx)
+   ->  Merge Join  (cost=xxx..xxx rows=1000 width=xxx)
          Merge Cond: (t1.id = t2.id)
-         ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-         ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-   ->  Sort  (cost=xxx rows=100 width=xxx)
+         ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+         ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
+   ->  Sort  (cost=xxx..xxx rows=100 width=xxx)
          Sort Key: t3.id
-         ->  Seq Scan on t3  (cost=xxx rows=100 width=xxx)
-(9 rows)
+         ->  Seq Scan on t3  (cost=xxx..xxx rows=100 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t2 #22) */
@@ -8413,18 +9004,17 @@ error hint:
 
 \o
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                     QUERY PLAN                                     
-------------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=1 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=1 width=xxx)
    Merge Cond: (t1.id = t3.id)
-   ->  Merge Join  (cost=xxx rows=22 width=xxx)
+   ->  Merge Join  (cost=xxx..xxx rows=22 width=xxx)
          Merge Cond: (t1.id = t2.id)
-         ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-         ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-   ->  Sort  (cost=xxx rows=100 width=xxx)
+         ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+         ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
+   ->  Sort  (cost=xxx..xxx rows=100 width=xxx)
          Sort Key: t3.id
-         ->  Seq Scan on t3  (cost=xxx rows=100 width=xxx)
-(9 rows)
+         ->  Seq Scan on t3  (cost=xxx..xxx rows=100 width=xxx)
 
 \o results/pg_hint_plan.tmpout
 /*+ Rows(t1 t3 *10) */
@@ -8439,17 +9029,92 @@ error hint:
 \o
 set max_parallel_workers_per_gather to DEFAULT;
 \! sql/maskout.sh results/pg_hint_plan.tmpout
-                                     QUERY PLAN                                     
-------------------------------------------------------------------------------------
- Merge Join  (cost=xxx rows=100 width=xxx)
+  QUERY PLAN
+----------------
+ Merge Join  (cost=xxx..xxx rows=100 width=xxx)
    Merge Cond: (t1.id = t3.id)
-   ->  Merge Join  (cost=xxx rows=1000 width=xxx)
+   ->  Merge Join  (cost=xxx..xxx rows=1000 width=xxx)
          Merge Cond: (t1.id = t2.id)
-         ->  Index Scan using t1_pkey on t1  (cost=xxx rows=10000 width=xxx)
-         ->  Index Scan using t2_pkey on t2  (cost=xxx rows=1000 width=xxx)
-   ->  Sort  (cost=xxx rows=100 width=xxx)
+         ->  Index Scan using t1_pkey on t1  (cost=xxx..xxx rows=10000 width=xxx)
+         ->  Index Scan using t2_pkey on t2  (cost=xxx..xxx rows=1000 width=xxx)
+   ->  Sort  (cost=xxx..xxx rows=100 width=xxx)
          Sort Key: t3.id
-         ->  Seq Scan on t3  (cost=xxx rows=100 width=xxx)
-(9 rows)
+         ->  Seq Scan on t3  (cost=xxx..xxx rows=100 width=xxx)
 
 \! rm results/pg_hint_plan.tmpout
+-- hint error level
+set client_min_messages to 'DEBUG1';
+set pg_hint_plan.debug_level to 'verbose';
+/*+ SeqScan( */ SELECT 1;
+INFO:  pg_hint_plan: hint syntax error at or near ""
+DETAIL:  Closing parenthesis is necessary.
+ ?column? 
+----------
+        1
+(1 row)
+
+/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0;
+LOG:  pg_hint_plan:
+used hint:
+SeqScan(t1)
+not used hint:
+duplication hint:
+error hint:
+
+ id | val 
+----+-----
+(0 rows)
+
+set pg_hint_plan.message_level to 'DEBUG1';
+set pg_hint_plan.parse_messages to 'NOTICE';
+/*+ SeqScan( */ SELECT 1;
+NOTICE:  pg_hint_plan: hint syntax error at or near ""
+DETAIL:  Closing parenthesis is necessary.
+ ?column? 
+----------
+        1
+(1 row)
+
+/*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0;
+DEBUG:  pg_hint_plan:
+used hint:
+SeqScan(t1)
+not used hint:
+duplication hint:
+error hint:
+
+ id | val 
+----+-----
+(0 rows)
+
+-- all hint types together
+/*+ SeqScan(t1) MergeJoin(t1 t2) Leading(t1 t2) Rows(t1 t2 +10) Parallel(t1 8 hard) Set(random_page_cost 2.0)*/
+EXPLAIN (costs off) SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON (t3.id = t2.id);
+DEBUG:  adjusted rows 1000 to 1010
+DEBUG:  pg_hint_plan:
+used hint:
+SeqScan(t1)
+MergeJoin(t1 t2)
+Leading(t1 t2)
+Set(random_page_cost 2.0)
+Rows(t1 t2 +10)
+Parallel(t1 8 hard)
+not used hint:
+duplication hint:
+error hint:
+
+                   QUERY PLAN                    
+-------------------------------------------------
+ Nested Loop
+   ->  Merge Join
+         Merge Cond: (t2.id = t1.id)
+         ->  Index Scan using t2_pkey on t2
+         ->  Sort
+               Sort Key: t1.id
+               ->  Gather
+                     Workers Planned: 8
+                     ->  Parallel Seq Scan on t1
+   ->  Index Scan using t3_pkey on t3
+         Index Cond: (id = t1.id)
+(11 rows)
+