PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
shippable.c File Reference
#include "postgres.h"
#include "postgres_fdw.h"
#include "access/transam.h"
#include "catalog/dependency.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

static void InitializeShippableCache ( void  )
static

Definition at line 93 of file shippable.c.

References CacheRegisterSyscacheCallback(), HASHCTL::entrysize, FOREIGNSERVEROID, HASH_BLOBS, hash_create(), HASH_ELEM, InvalidateShippableCacheCallback(), HASHCTL::keysize, and MemSet.

Referenced by is_shippable().

94 {
95  HASHCTL ctl;
96 
97  /* Create the hash table. */
98  MemSet(&ctl, 0, sizeof(ctl));
99  ctl.keysize = sizeof(ShippableCacheKey);
100  ctl.entrysize = sizeof(ShippableCacheEntry);
102  hash_create("Shippability cache", 256, &ctl, HASH_ELEM | HASH_BLOBS);
103 
104  /* Set up invalidation callback on pg_foreign_server. */
107  (Datum) 0);
108 }
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:853
#define HASH_BLOBS
Definition: hsearch.h:88
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1381
uintptr_t Datum
Definition: postgres.h:374
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
static void InvalidateShippableCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
Definition: shippable.c:67
static HTAB * ShippableCacheHash
Definition: shippable.c:36
static void InvalidateShippableCacheCallback ( Datum  arg,
int  cacheid,
uint32  hashvalue 
)
static

Definition at line 67 of file shippable.c.

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

Referenced by InitializeShippableCache().

68 {
70  ShippableCacheEntry *entry;
71 
72  /*
73  * In principle we could flush only cache entries relating to the
74  * pg_foreign_server entry being outdated; but that would be more
75  * complicated, and it's probably not worth the trouble. So for now, just
76  * flush all entries.
77  */
79  while ((entry = (ShippableCacheEntry *) hash_seq_search(&status)) != NULL)
80  {
82  (void *) &entry->key,
84  NULL) == NULL)
85  elog(ERROR, "hash table corrupted");
86  }
87 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
#define ERROR
Definition: elog.h:43
#define NULL
Definition: c.h:226
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1353
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1343
static HTAB * ShippableCacheHash
Definition: shippable.c:36
#define elog
Definition: elog.h:219
ShippableCacheKey key
Definition: shippable.c:53
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:222
bool is_builtin ( Oid  objectId)

Definition at line 155 of file shippable.c.

References FirstBootstrapObjectId.

Referenced by deparse_type_name(), and is_shippable().

156 {
157  return (objectId < FirstBootstrapObjectId);
158 }
#define FirstBootstrapObjectId
Definition: transam.h:93
bool is_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfo fpinfo 
)

Definition at line 165 of file shippable.c.

References ShippableCacheKey::classid, HASH_ENTER, HASH_FIND, hash_search(), InitializeShippableCache(), is_builtin(), lookup_shippable(), NIL, NULL, ShippableCacheKey::objid, PgFdwRelationInfo::server, ForeignServer::serverid, ShippableCacheKey::serverid, ShippableCacheEntry::shippable, and PgFdwRelationInfo::shippable_extensions.

Referenced by foreign_expr_walker().

166 {
167  ShippableCacheKey key;
168  ShippableCacheEntry *entry;
169 
170  /* Built-in objects are presumed shippable. */
171  if (is_builtin(objectId))
172  return true;
173 
174  /* Otherwise, give up if user hasn't specified any shippable extensions. */
175  if (fpinfo->shippable_extensions == NIL)
176  return false;
177 
178  /* Initialize cache if first time through. */
179  if (!ShippableCacheHash)
181 
182  /* Set up cache hash key */
183  key.objid = objectId;
184  key.classid = classId;
185  key.serverid = fpinfo->server->serverid;
186 
187  /* See if we already cached the result. */
188  entry = (ShippableCacheEntry *)
190  (void *) &key,
191  HASH_FIND,
192  NULL);
193 
194  if (!entry)
195  {
196  /* Not found in cache, so perform shippability lookup. */
197  bool shippable = lookup_shippable(objectId, classId, fpinfo);
198 
199  /*
200  * Don't create a new hash entry until *after* we have the shippable
201  * result in hand, as the underlying catalog lookups might trigger a
202  * cache invalidation.
203  */
204  entry = (ShippableCacheEntry *)
206  (void *) &key,
207  HASH_ENTER,
208  NULL);
209 
210  entry->shippable = shippable;
211  }
212 
213  return entry->shippable;
214 }
#define NIL
Definition: pg_list.h:69
bool is_builtin(Oid objectId)
Definition: shippable.c:155
ForeignServer * server
Definition: postgres_fdw.h:78
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
static void InitializeShippableCache(void)
Definition: shippable.c:93
static bool lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
Definition: shippable.c:119
#define NULL
Definition: c.h:226
static HTAB * ShippableCacheHash
Definition: shippable.c:36
List * shippable_extensions
Definition: postgres_fdw.h:74
Oid serverid
Definition: foreign.h:47
static bool lookup_shippable ( Oid  objectId,
Oid  classId,
PgFdwRelationInfo fpinfo 
)
static

Definition at line 119 of file shippable.c.

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

Referenced by is_shippable().

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

Variable Documentation

HTAB* ShippableCacheHash = NULL
static

Definition at line 36 of file shippable.c.