From: Teodor Sigaev Date: Mon, 3 Aug 2026 14:33:24 +0000 (+0300) Subject: Fix support RTE_RELATION X-Git-Url: http://www.sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;p=plantuner.git Fix support RTE_RELATION Andey Bille & Vlada Pogozhelskaya --- diff --git a/expected/plantuner.out b/expected/plantuner.out index 70d2bca..7bba940 100644 --- a/expected/plantuner.out +++ b/expected/plantuner.out @@ -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; diff --git a/plantuner.c b/plantuner.c index d31dbbb..b1c1e54 100644 --- a/plantuner.c +++ b/plantuner.c @@ -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 diff --git a/sql/plantuner.sql b/sql/plantuner.sql index ddd6fcc..759938e 100644 --- a/sql/plantuner.sql +++ b/sql/plantuner.sql @@ -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;