diff options
| author | Mason Sharp | 2010-12-23 20:10:38 +0000 |
|---|---|---|
| committer | Pavan Deolasee | 2011-05-19 16:45:26 +0000 |
| commit | d6d2d3d925f571b0b58ff6b4f6504d88e96bb342 (patch) | |
| tree | 46934a7eccee6a1c45edcbd68c5e7d52d0387b3e /src/include | |
| parent | 5ea02d34bd8584fadd738437bbed1155162a362f (diff) | |
Add support for single-step prepared statements.
Works for both named and unnamed prepared statements,
works for PREPARE and EXECUTE commands.
The Coordinator tracks a list of the prepared statements,
and prepares them in turn on Data Nodes, and only on demand,
when they are first executed on the target node(s).
At the end of a transaction, if there are still prepared
statements that exist for the session, the connections
are not released to the pool. (We should do something
similar for temporary tables.)
This commit also changes an existing kluge with using the
SQL string in some cases, and now deparses from the Query tree
instead.
Written by Andrei Martsinchyk, multi-step check added by me.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/commands/prepare.h | 16 | ||||
| -rw-r--r-- | src/include/executor/tuptable.h | 3 | ||||
| -rw-r--r-- | src/include/pgxc/execRemote.h | 4 | ||||
| -rw-r--r-- | src/include/pgxc/locator.h | 6 | ||||
| -rw-r--r-- | src/include/pgxc/planner.h | 5 | ||||
| -rw-r--r-- | src/include/utils/builtins.h | 2 |
6 files changed, 36 insertions, 0 deletions
diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h index f52f001289..b6f5afdb0e 100644 --- a/src/include/commands/prepare.h +++ b/src/include/commands/prepare.h @@ -33,6 +33,15 @@ typedef struct TimestampTz prepare_time; /* the time when the stmt was prepared */ } PreparedStatement; +#ifdef PGXC +typedef struct +{ + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + int nodenum; /* number of nodes where statement is active */ + int nodes[0]; /* node ids where statement is active */ +} DatanodeStatement; +#endif /* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */ extern void PrepareQuery(PrepareStmt *stmt, const char *queryString); @@ -62,4 +71,11 @@ extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt); void DropAllPreparedStatements(void); +#ifdef PGXC +extern DatanodeStatement *FetchDatanodeStatement(const char *stmt_name, bool throwError); +extern bool ActivateDatanodeStatementOnNode(const char *stmt_name, int node); +extern bool HaveActiveDatanodeStatements(void); +extern void DropDatanodeStatement(const char *stmt_name); +#endif + #endif /* PREPARE_H */ diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h index 0c2c4fe0a2..3e218bfc20 100644 --- a/src/include/executor/tuptable.h +++ b/src/include/executor/tuptable.h @@ -187,6 +187,9 @@ extern TupleTableSlot *ExecStoreVirtualTuple(TupleTableSlot *slot); extern TupleTableSlot *ExecStoreAllNullTuple(TupleTableSlot *slot); extern HeapTuple ExecCopySlotTuple(TupleTableSlot *slot); extern MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot); +#ifdef PGXC +extern int ExecCopySlotDatarow(TupleTableSlot *slot, char **datarow); +#endif extern HeapTuple ExecFetchSlotTuple(TupleTableSlot *slot); extern MinimalTuple ExecFetchSlotMinimalTuple(TupleTableSlot *slot); extern Datum ExecFetchSlotTupleDatum(TupleTableSlot *slot); diff --git a/src/include/pgxc/execRemote.h b/src/include/pgxc/execRemote.h index a3c1868422..c5c45c0162 100644 --- a/src/include/pgxc/execRemote.h +++ b/src/include/pgxc/execRemote.h @@ -144,5 +144,9 @@ extern void BufferConnection(PGXCNodeHandle *conn); extern void ExecRemoteQueryReScan(RemoteQueryState *node, ExprContext *exprCtxt); +extern int ParamListToDataRow(ParamListInfo params, char** result); + +extern void ExecCloseRemoteStatement(const char *stmt_name, List *nodelist); + extern int primary_data_node; #endif diff --git a/src/include/pgxc/locator.h b/src/include/pgxc/locator.h index ee28c5a402..a6d1d531a3 100644 --- a/src/include/pgxc/locator.h +++ b/src/include/pgxc/locator.h @@ -26,6 +26,8 @@ #define HASH_MASK 0x00000FFF; #define IsReplicated(x) (x->locatorType == LOCATOR_TYPE_REPLICATED) + +#include "nodes/primnodes.h" #include "utils/relcache.h" @@ -76,6 +78,10 @@ typedef struct List *nodelist; char baselocatortype; TableUsageType tableusagetype; /* track pg_catalog usage */ + Expr *expr; /* expression to evaluate at execution time if planner + * can not determine execution nodes */ + Oid relid; /* Relation to determine execution nodes */ + RelationAccessType accesstype; /* Access type to determine execution nodes */ } ExecNodes; diff --git a/src/include/pgxc/planner.h b/src/include/pgxc/planner.h index bb1f934be9..61cb6d3291 100644 --- a/src/include/pgxc/planner.h +++ b/src/include/pgxc/planner.h @@ -85,9 +85,14 @@ typedef struct SimpleDistinct *distinct; bool read_only; /* do not use 2PC when committing read only steps */ bool force_autocommit; /* some commands like VACUUM require autocommit mode */ + char *statement; /* if specified use it as a PreparedStatement name on data nodes */ char *cursor; /* if specified use it as a Portal name on data nodes */ RemoteQueryExecType exec_type; + /* Support for parameters */ + char *paramval_data; /* parameter data, format is like in BIND */ + int paramval_len; /* length of parameter values data */ + char *relname; bool remotejoin; /* True if this is a reduced remote join */ bool partitioned_replicated; /* True if reduced and contains replicated-partitioned join */ diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 6e26da755d..4a56f9fb11 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -15,6 +15,7 @@ #define BUILTINS_H #include "fmgr.h" +#include "lib/stringinfo.h" #include "nodes/parsenodes.h" /* @@ -598,6 +599,7 @@ extern char *deparse_expression(Node *expr, List *dpcontext, #ifdef PGXC extern List *deparse_context_for_remotequery(const char *aliasname, Oid relid); extern List *deparse_context_for(const char *aliasname, Oid relid); +extern void deparse_query(Query *query, StringInfo buf, List *parentnamespace); #endif extern List *deparse_context_for_plan(Node *plan, Node *outer_plan, List *rtable, List *subplans); |
