mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
d894941663
The user can whitelist specified extension(s) in the foreign server's options, whereupon we will treat immutable functions and operators of those extensions as candidates to be sent for remote execution. Whitelisting an extension in this way basically promises that the extension exists on the remote server and behaves compatibly with the local instance. We have no way to prove that formally, so we have to rely on the user to get it right. But this seems like something that people can usually get right in practice. We might in future allow functions and operators to be whitelisted individually, but extension granularity is a very convenient special case, so it got done first. The patch as-committed lacks any regression tests, which is unfortunate, but introducing dependencies on other extensions for testing purposes would break "make installcheck" scenarios, which is worse. I have some ideas about klugy ways around that, but it seems like material for a separate patch. For the moment, leave the problem open. Paul Ramsey, hacked up a bit more by me
123 lines
3.9 KiB
C
123 lines
3.9 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* postgres_fdw.h
|
|
* Foreign-data wrapper for remote PostgreSQL servers
|
|
*
|
|
* Portions Copyright (c) 2012-2015, PostgreSQL Global Development Group
|
|
*
|
|
* IDENTIFICATION
|
|
* contrib/postgres_fdw/postgres_fdw.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef POSTGRES_FDW_H
|
|
#define POSTGRES_FDW_H
|
|
|
|
#include "foreign/foreign.h"
|
|
#include "lib/stringinfo.h"
|
|
#include "nodes/relation.h"
|
|
#include "utils/relcache.h"
|
|
|
|
#include "libpq-fe.h"
|
|
|
|
/*
|
|
* FDW-specific planner information kept in RelOptInfo.fdw_private for a
|
|
* foreign table. This information is collected by postgresGetForeignRelSize.
|
|
*/
|
|
typedef struct PgFdwRelationInfo
|
|
{
|
|
/* baserestrictinfo clauses, broken down into safe and unsafe subsets. */
|
|
List *remote_conds;
|
|
List *local_conds;
|
|
|
|
/* Bitmap of attr numbers we need to fetch from the remote server. */
|
|
Bitmapset *attrs_used;
|
|
|
|
/* Cost and selectivity of local_conds. */
|
|
QualCost local_conds_cost;
|
|
Selectivity local_conds_sel;
|
|
|
|
/* Estimated size and cost for a scan with baserestrictinfo quals. */
|
|
double rows;
|
|
int width;
|
|
Cost startup_cost;
|
|
Cost total_cost;
|
|
|
|
/* Options extracted from catalogs. */
|
|
bool use_remote_estimate;
|
|
Cost fdw_startup_cost;
|
|
Cost fdw_tuple_cost;
|
|
List *shippable_extensions; /* OIDs of whitelisted extensions */
|
|
|
|
/* Cached catalog information. */
|
|
ForeignTable *table;
|
|
ForeignServer *server;
|
|
UserMapping *user; /* only set in use_remote_estimate mode */
|
|
} PgFdwRelationInfo;
|
|
|
|
/* in postgres_fdw.c */
|
|
extern int set_transmission_modes(void);
|
|
extern void reset_transmission_modes(int nestlevel);
|
|
|
|
/* in connection.c */
|
|
extern PGconn *GetConnection(ForeignServer *server, UserMapping *user,
|
|
bool will_prep_stmt);
|
|
extern void ReleaseConnection(PGconn *conn);
|
|
extern unsigned int GetCursorNumber(PGconn *conn);
|
|
extern unsigned int GetPrepStmtNumber(PGconn *conn);
|
|
extern void pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
|
|
bool clear, const char *sql);
|
|
|
|
/* in option.c */
|
|
extern int ExtractConnectionOptions(List *defelems,
|
|
const char **keywords,
|
|
const char **values);
|
|
extern List *ExtractExtensionList(const char *extensionsString,
|
|
bool warnOnMissing);
|
|
|
|
/* in deparse.c */
|
|
extern void classifyConditions(PlannerInfo *root,
|
|
RelOptInfo *baserel,
|
|
List *input_conds,
|
|
List **remote_conds,
|
|
List **local_conds);
|
|
extern bool is_foreign_expr(PlannerInfo *root,
|
|
RelOptInfo *baserel,
|
|
Expr *expr);
|
|
extern void deparseSelectSql(StringInfo buf,
|
|
PlannerInfo *root,
|
|
RelOptInfo *baserel,
|
|
Bitmapset *attrs_used,
|
|
List **retrieved_attrs);
|
|
extern void appendWhereClause(StringInfo buf,
|
|
PlannerInfo *root,
|
|
RelOptInfo *baserel,
|
|
List *exprs,
|
|
bool is_first,
|
|
List **params);
|
|
extern void deparseInsertSql(StringInfo buf, PlannerInfo *root,
|
|
Index rtindex, Relation rel,
|
|
List *targetAttrs, bool doNothing, List *returningList,
|
|
List **retrieved_attrs);
|
|
extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
|
|
Index rtindex, Relation rel,
|
|
List *targetAttrs, List *returningList,
|
|
List **retrieved_attrs);
|
|
extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
|
|
Index rtindex, Relation rel,
|
|
List *returningList,
|
|
List **retrieved_attrs);
|
|
extern void deparseAnalyzeSizeSql(StringInfo buf, Relation rel);
|
|
extern void deparseAnalyzeSql(StringInfo buf, Relation rel,
|
|
List **retrieved_attrs);
|
|
extern void deparseStringLiteral(StringInfo buf, const char *val);
|
|
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
|
|
extern void appendOrderByClause(StringInfo buf, PlannerInfo *root,
|
|
RelOptInfo *baserel, List *pathkeys);
|
|
|
|
/* in shippable.c */
|
|
extern bool is_builtin(Oid objectId);
|
|
extern bool is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo);
|
|
|
|
#endif /* POSTGRES_FDW_H */
|