]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Replace get_relation_info_hook with build_simple_rel_hook.
authorRobert Haas <rhaas@postgresql.org>
Mon, 9 Mar 2026 13:48:26 +0000 (09:48 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 9 Mar 2026 13:48:26 +0000 (09:48 -0400)
For a long time, PostgreSQL has had a get_relation_info_hook which
plugins can use to editorialize on the information that
get_relation_info obtains from the catalogs. However, this hook is
only called for baserels of type RTE_RELATION, and there is
potential utility in a similar call back for other types of
RTEs. This might have had utility even before commit
4020b370f214315b8c10430301898ac21658143f added pgs_mask to
RelOptInfo, but it certainly has utility now.

So, move the callback up one level, deleting get_relation_info_hook and
adding build_simple_rel_hook instead. The new callback is called just
slightly later than before and with slightly different arguments, but it
should be fairly straightforward to adjust existing code that currently
uses get_relation_info_hook: the values previously available as
relationObjectId and inhparent are now available via rte->relid and
rte->inh, and calls where rte->rtekind != RTE_RELATION can be ignored if
desired.

Reviewed-by: Alexandra Wang <alexandra.wang.oss@gmail.com>
Discussion: http://postgr.es/m/CA%2BTgmoYg8uUWyco7Pb3HYLMBRQoO6Zh9hwgm27V39Pb6Pdf%3Dug%40mail.gmail.com

src/backend/optimizer/util/plancat.c
src/backend/optimizer/util/relnode.c
src/include/optimizer/pathnode.h
src/include/optimizer/plancat.h

index d63e7390be764c1d10096d0ec41662912de88ffb..b2fbd6a082bbca674bcc113b7f4632a5f2a38948 100644 (file)
@@ -57,9 +57,6 @@
 /* GUC parameter */
 int                    constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION;
 
-/* Hook for plugins to get control in get_relation_info() */
-get_relation_info_hook_type get_relation_info_hook = NULL;
-
 typedef struct NotnullHashEntry
 {
        Oid                     relid;                  /* OID of the relation */
@@ -571,17 +568,6 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
                set_relation_partition_info(root, rel, relation);
 
        table_close(relation, NoLock);
-
-       /*
-        * Allow a plugin to editorialize on the info we obtained from the
-        * catalogs.  Actions might include altering the assumed relation size,
-        * removing an index, or adding a hypothetical index to the indexlist.
-        *
-        * An extension can also modify rel->pgs_mask here to control path
-        * generation.
-        */
-       if (get_relation_info_hook)
-               (*get_relation_info_hook) (root, relationObjectId, inhparent, rel);
 }
 
 /*
index d21b4d3bb35631edaea6510efddd0fe3b829addd..91bcda34a378617382c9a49983db3c34be8d3954 100644 (file)
@@ -47,6 +47,9 @@ typedef struct JoinHashEntry
        RelOptInfo *join_rel;
 } JoinHashEntry;
 
+/* Hook for plugins to get control in build_simple_rel() */
+build_simple_rel_hook_type build_simple_rel_hook = NULL;
+
 /* Hook for plugins to get control during joinrel setup */
 joinrel_setup_hook_type joinrel_setup_hook = NULL;
 
@@ -394,6 +397,18 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
                        break;
        }
 
+       /*
+        * Allow a plugin to editorialize on the new RelOptInfo. This could
+        * involve editorializing on the information which get_relation_info
+        * obtained from the catalogs, such as altering the assumed relation size,
+        * removing an index, or adding a hypothetical index to the indexlist.
+        *
+        * An extension can also modify rel->pgs_mask here to control path
+        * generation.
+        */
+       if (build_simple_rel_hook)
+               (*build_simple_rel_hook) (root, rel, rte);
+
        /*
         * Apply the parent's quals to the child, with appropriate substitution of
         * variables.  If any resulting clause is reduced to constant FALSE or
index 938510400cc537412ac4eb24da91a9f7b24b251a..da2d9b384b5965960f244acfa5b66d250aa9cf21 100644 (file)
 #include "nodes/bitmapset.h"
 #include "nodes/pathnodes.h"
 
+/* Hook for plugins to get control in build_simple_rel() */
+typedef void (*build_simple_rel_hook_type) (PlannerInfo *root,
+                                                                                       RelOptInfo *rel,
+                                                                                       RangeTblEntry *rte);
+extern PGDLLIMPORT build_simple_rel_hook_type build_simple_rel_hook;
+
 /*
  * Everything in subpaths or partial_subpaths will become part of the
  * Append node's subpaths list. Partial and non-partial subpaths can be
index 8d7cc6d9886b167b25eeb000c6aa6a78b8caff1e..09baf1a691643bbfe10bd7b41137539e9d00374b 100644 (file)
 #include "nodes/pathnodes.h"
 #include "utils/relcache.h"
 
-/* Hook for plugins to get control in get_relation_info() */
-typedef void (*get_relation_info_hook_type) (PlannerInfo *root,
-                                                                                        Oid relationObjectId,
-                                                                                        bool inhparent,
-                                                                                        RelOptInfo *rel);
-extern PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook;
-
-
 extern void get_relation_info(PlannerInfo *root, Oid relationObjectId,
                                                          bool inhparent, RelOptInfo *rel);