Skip to content

FDW extension patch #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes from Andres Freund patch review
  • Loading branch information
pramsey committed Oct 4, 2015
commit ed33e7489601e659f436d6afda3cce28304eba50
10 changes: 5 additions & 5 deletions contrib/postgres_fdw/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ foreign_expr_walker(Node *node,
* semantics on remote side.
*/
if (!is_builtin(fe->funcid) &&
!is_shippable(fe->funcid, fpinfo->extensions))
!is_shippable(fe->funcid, ProcedureRelationId, fpinfo->extensions))
return false;

/*
Expand Down Expand Up @@ -431,7 +431,7 @@ foreign_expr_walker(Node *node,
* too.)
*/
if (!is_builtin(oe->opno) &&
!is_shippable(oe->opno, fpinfo->extensions))
!is_shippable(oe->opno, OperatorRelationId, fpinfo->extensions))
return false;

/*
Expand Down Expand Up @@ -472,7 +472,7 @@ foreign_expr_walker(Node *node,
* Again, only built-in operators can be sent to remote.
*/
if (!is_builtin(oe->opno) &&
!is_shippable(oe->opno, fpinfo->extensions))
!is_shippable(oe->opno, OperatorRelationId, fpinfo->extensions))
return false;

/*
Expand Down Expand Up @@ -624,7 +624,7 @@ foreign_expr_walker(Node *node,
*/
if (check_type &&
!is_builtin(exprType(node)) &&
!is_shippable(exprType(node), fpinfo->extensions))
!is_shippable(exprType(node), TypeRelationId, fpinfo->extensions))
return false;

/*
Expand Down Expand Up @@ -1445,7 +1445,7 @@ deparseConst(Const *node, deparse_expr_cxt *context)
* but references to built-in types shouldn't be.
*/
appendStringInfo(buf, "::%s",
is_shippable(node->consttype, fpinfo->extensions) ?
is_shippable(node->consttype, TypeRelationId, fpinfo->extensions) ?
format_type_be_qualified(node->consttype) :
format_type_with_typemod(node->consttype, node->consttypmod));
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/postgres_fdw/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
}
else if (strcmp(def->defname, "extensions") == 0)
{
/* this must have already-installed extensions */
/* check that the requested extensions are actually installed */
(void) ExtractExtensionList(defGetString(def), false);
}
}
Expand Down Expand Up @@ -157,10 +157,10 @@ InitPgFdwOptions(void)
/* cost factors */
{"fdw_startup_cost", ForeignServerRelationId, false},
{"fdw_tuple_cost", ForeignServerRelationId, false},
/* updatable is available on both server and table */
/* updatable option is available on both server and table */
{"updatable", ForeignServerRelationId, false},
{"updatable", ForeignTableRelationId, false},
/* extensions is available on server */
/* "extensions" option is available on server */
{"extensions", ForeignServerRelationId, false},
{NULL, InvalidOid, false}
};
Expand Down Expand Up @@ -307,7 +307,7 @@ ExtractConnectionOptions(List *defelems, const char **keywords,
* Parse a comma-separated string and return a List of the Oids of the
* extensions in the string. If an extension provided cannot be looked
* up in the catalog (it hasn't been installed or doesn't exist) then
* throw up an error.
* raise an error.
*/
List *
ExtractExtensionList(char *extensionString, bool populateList)
Expand Down
4 changes: 2 additions & 2 deletions contrib/postgres_fdw/postgres_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct PgFdwRelationInfo
Cost fdw_startup_cost;
Cost fdw_tuple_cost;

/* Optional extensions to support (list of oid) */
/* Optional extensions to support (list of Oids). */
List *extensions;

/* Cached catalog information. */
Expand Down Expand Up @@ -78,7 +78,7 @@ extern List *ExtractExtensionList(char *extensionString,
bool populateList);

/* in shippable.c */
extern bool is_shippable(Oid procnumber, List *extension_list);
extern bool is_shippable(Oid objnumber, Oid classnumber, List *extension_list);

/* in deparse.c */
extern void classifyConditions(PlannerInfo *root,
Expand Down
22 changes: 14 additions & 8 deletions contrib/postgres_fdw/shippable.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct
{
/* extension the object appears within, or InvalidOid if none */
Oid objid;
Oid classid;
} ShippableCacheKey;

typedef struct
Expand Down Expand Up @@ -89,24 +90,23 @@ InitializeShippableCache(void)
}

/*
* Returns true if given operator/function is part of an extension declared in
* Returns true if given operator/function is part of an extension listed in
* the server options.
*/
static bool
lookup_shippable(Oid objnumber, List *extension_list)
lookup_shippable(Oid objnumber, Oid classnumber, List *extension_list)
{
static int nkeys = 1;
static int nkeys = 2;
ScanKeyData key[nkeys];
HeapTuple tup;
Relation depRel;
SysScanDesc scan;
bool is_shippable = false;

/* Always return false if we don't have any declared extensions */
/* Always return false if the user hasn't set the "extensions" option */
if (extension_list == NIL)
return false;

/* We need this relation to scan */
depRel = heap_open(DependRelationId, RowExclusiveLock);

/*
Expand All @@ -115,6 +115,11 @@ lookup_shippable(Oid objnumber, List *extension_list)
* is an extension declared by the user in the options
*/
ScanKeyInit(&key[0],
Anum_pg_depend_classid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(classnumber));

ScanKeyInit(&key[1],
Anum_pg_depend_objid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(objnumber));
Expand Down Expand Up @@ -147,12 +152,12 @@ lookup_shippable(Oid objnumber, List *extension_list)
* part of a declared extension if it is not cached.
*/
bool
is_shippable(Oid objnumber, List *extension_list)
is_shippable(Oid objnumber, Oid classnumber, List *extension_list)
{
ShippableCacheKey key;
ShippableCacheEntry *entry;

/* Always return false if we don't have any declared extensions */
/* Always return false if the user hasn't set the "extensions" option */
if (extension_list == NIL)
return false;

Expand All @@ -164,6 +169,7 @@ is_shippable(Oid objnumber, List *extension_list)
memset(&key, 0, sizeof(key));

key.objid = objnumber;
key.classid = classnumber;

entry = (ShippableCacheEntry *)
hash_search(ShippableCacheHash,
Expand All @@ -180,7 +186,7 @@ is_shippable(Oid objnumber, List *extension_list)
* In the future we could additionally have a whitelist of functions
* declared one at a time.
*/
bool shippable = lookup_shippable(objnumber, extension_list);
bool shippable = lookup_shippable(objnumber, classnumber, extension_list);

entry = (ShippableCacheEntry *)
hash_search(ShippableCacheHash,
Expand Down