PostgreSQL Source Code  git master
shippable.c File Reference
#include "postgres.h"
#include "access/transam.h"
#include "catalog/dependency.h"
#include "postgres_fdw.h"
#include "utils/hsearch.h"
#include "utils/inval.h"
#include "utils/syscache.h"
Include dependency graph for shippable.c:

Go to the source code of this file.

Data Structures

struct  ShippableCacheKey
 
struct  ShippableCacheEntry
 

Functions

static void InvalidateShippableCacheCallback (Datum arg, int cacheid, uint32 hashvalue)
 
static void InitializeShippableCache (void)
 
static bool lookup_shippable (Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
 
bool is_builtin (Oid objectId)
 
bool is_shippable (Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
 

Variables

static HTABShippableCacheHash = NULL
 

Function Documentation

◆ InitializeShippableCache()

static void InitializeShippableCache ( void  )
static

Definition at line 91 of file shippable.c.

92 {
93  HASHCTL ctl;
94 
95  /* Create the hash table. */
96  ctl.keysize = sizeof(ShippableCacheKey);
97  ctl.entrysize = sizeof(ShippableCacheEntry);
99  hash_create("Shippability cache", 256, &ctl, HASH_ELEM | HASH_BLOBS);
100 
101  /* Set up invalidation callback on pg_foreign_server. */
102  CacheRegisterSyscacheCallback(FOREIGNSERVEROID,
104  (Datum) 0);
105 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1704
uintptr_t Datum
Definition: postgres.h:64
tree ctl
Definition: radixtree.h:1855
static HTAB * ShippableCacheHash
Definition: shippable.c:34
static void InvalidateShippableCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
Definition: shippable.c:65

References CacheRegisterSyscacheCallback(), ctl, HASH_BLOBS, hash_create(), HASH_ELEM, InvalidateShippableCacheCallback(), and ShippableCacheHash.

Referenced by is_shippable().

◆ InvalidateShippableCacheCallback()

static void InvalidateShippableCacheCallback ( Datum  arg,
int  cacheid,
uint32  hashvalue 
)
static

Definition at line 65 of file shippable.c.

66 {
67  HASH_SEQ_STATUS status;
68  ShippableCacheEntry *entry;
69 
70  /*
71  * In principle we could flush only cache entries relating to the
72  * pg_foreign_server entry being outdated; but that would be more
73  * complicated, and it's probably not worth the trouble. So for now, just
74  * flush all entries.
75  */
77  while ((entry = (ShippableCacheEntry *) hash_seq_search(&status)) != NULL)
78  {
80  &entry->key,
82  NULL) == NULL)
83  elog(ERROR, "hash table corrupted");
84  }
85 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1420
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1385
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
@ HASH_REMOVE
Definition: hsearch.h:115
ShippableCacheKey key
Definition: shippable.c:51

References elog, ERROR, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), ShippableCacheEntry::key, and ShippableCacheHash.

Referenced by InitializeShippableCache().

◆ is_builtin()

bool is_builtin ( Oid  objectId)

Definition at line 152 of file shippable.c.

153 {
154  return (objectId < FirstGenbkiObjectId);
155 }
#define FirstGenbkiObjectId
Definition: transam.h:195

References FirstGenbkiObjectId.

Referenced by deparse_type_name(), and is_shippable().

◆ is_shippable()

bool is_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfo fpinfo 
)

Definition at line 162 of file shippable.c.

163 {
165  ShippableCacheEntry *entry;
166 
167  /* Built-in objects are presumed shippable. */
168  if (is_builtin(objectId))
169  return true;
170 
171  /* Otherwise, give up if user hasn't specified any shippable extensions. */
172  if (fpinfo->shippable_extensions == NIL)
173  return false;
174 
175  /* Initialize cache if first time through. */
176  if (!ShippableCacheHash)
178 
179  /* Set up cache hash key */
180  key.objid = objectId;
181  key.classid = classId;
182  key.serverid = fpinfo->server->serverid;
183 
184  /* See if we already cached the result. */
185  entry = (ShippableCacheEntry *)
187 
188  if (!entry)
189  {
190  /* Not found in cache, so perform shippability lookup. */
191  bool shippable = lookup_shippable(objectId, classId, fpinfo);
192 
193  /*
194  * Don't create a new hash entry until *after* we have the shippable
195  * result in hand, as the underlying catalog lookups might trigger a
196  * cache invalidation.
197  */
198  entry = (ShippableCacheEntry *)
200 
201  entry->shippable = shippable;
202  }
203 
204  return entry->shippable;
205 }
@ HASH_FIND
Definition: hsearch.h:113
@ HASH_ENTER
Definition: hsearch.h:114
#define NIL
Definition: pg_list.h:68
static bool lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:116
bool is_builtin(Oid objectId)
Definition: shippable.c:152
static void InitializeShippableCache(void)
Definition: shippable.c:91
Oid serverid
Definition: foreign.h:36
List * shippable_extensions
Definition: postgres_fdw.h:82
ForeignServer * server
Definition: postgres_fdw.h:87

References HASH_ENTER, HASH_FIND, hash_search(), InitializeShippableCache(), is_builtin(), sort-test::key, lookup_shippable(), NIL, PgFdwRelationInfo::server, ForeignServer::serverid, ShippableCacheEntry::shippable, PgFdwRelationInfo::shippable_extensions, and ShippableCacheHash.

Referenced by add_foreign_ordered_paths(), foreign_expr_walker(), get_useful_pathkeys_for_relation(), and is_foreign_pathkey().

◆ lookup_shippable()

static bool lookup_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfo fpinfo 
)
static

Definition at line 116 of file shippable.c.

117 {
118  Oid extensionOid;
119 
120  /*
121  * Is object a member of some extension? (Note: this is a fairly
122  * expensive lookup, which is why we try to cache the results.)
123  */
124  extensionOid = getExtensionOfObject(classId, objectId);
125 
126  /* If so, is that extension in fpinfo->shippable_extensions? */
127  if (OidIsValid(extensionOid) &&
128  list_member_oid(fpinfo->shippable_extensions, extensionOid))
129  return true;
130 
131  return false;
132 }
#define OidIsValid(objectId)
Definition: c.h:729
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:722
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:732
unsigned int Oid
Definition: postgres_ext.h:31

References getExtensionOfObject(), list_member_oid(), OidIsValid, and PgFdwRelationInfo::shippable_extensions.

Referenced by is_shippable().

Variable Documentation

◆ ShippableCacheHash

HTAB* ShippableCacheHash = NULL
static