Fix support RTE_RELATION master
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 3 Aug 2026 14:33:24 +0000 (17:33 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 3 Aug 2026 14:33:24 +0000 (17:33 +0300)
Andey Bille & Vlada Pogozhelskaya

expected/plantuner.out
plantuner.c
sql/plantuner.sql

index 70d2bca..7bba940 100644 (file)
@@ -94,3 +94,10 @@ EXPLAIN (COSTS OFF) SELECT * FROM wow WHERE i = 0;
    Index Cond: (i = 0)
 (2 rows)
 
+SELECT 1 AS one;
+ one 
+-----
+   1
+(1 row)
+
+RESET ALL;
index d31dbbb..b1c1e54 100644 (file)
@@ -417,24 +417,33 @@ execPlantuner(PlannerInfo *root, Oid relationObjectId, bool inhparent,
                          RelOptInfo *rel)
 {
 #endif
-       Relation        relation;
-
-       relation = heap_open(relationObjectId, NoLock);
-       if (relation->rd_rel->relkind == RELKIND_RELATION)
+#if PG_VERSION_NUM >= 190000
+       if (rte->rtekind == RTE_RELATION &&
+               rte->relkind == RELKIND_RELATION)
+#endif
        {
-               if (fix_empty_table && RelationGetNumberOfBlocks(relation) == 0)
+               Relation        relation;
+
+#if PG_VERSION_NUM >= 190000
+               Assert(OidIsValid(relationObjectId));
+#endif
+               relation = heap_open(relationObjectId, NoLock);
+               if (relation->rd_rel->relkind == RELKIND_RELATION)
                {
-                       /*
-                        * estimate_rel_size() could be too pessimistic for particular
-                        * workload
-                        */
-                       rel->pages = 1.0;
-                       rel->tuples = 0.0;
-               }
+                       if (fix_empty_table && RelationGetNumberOfBlocks(relation) == 0)
+                       {
+                               /*
+                                * estimate_rel_size() could be too pessimistic for particular
+                                * workload
+                                */
+                               rel->pages = 1.0;
+                               rel->tuples = 0.0;
+                       }
 
-               indexFilter(root, relationObjectId, inhparent, rel);
+                       indexFilter(root, relationObjectId, inhparent, rel);
+               }
+               heap_close(relation, NoLock);
        }
-       heap_close(relation, NoLock);
 
        /*
         * Call next hook if it exists
index ddd6fcc..759938e 100644 (file)
@@ -49,3 +49,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM wow WHERE i = 0;
 
 RESET plantuner.only_index;
 EXPLAIN (COSTS OFF) SELECT * FROM wow WHERE i = 0;
+
+SELECT 1 AS one;
+RESET ALL;