2002-08-27 06:55:12 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* prepare.h
|
2003-05-05 02:44:56 +02:00
|
|
|
* PREPARE, EXECUTE and DEALLOCATE commands, and prepared-stmt storage
|
2002-08-27 06:55:12 +02:00
|
|
|
*
|
|
|
|
*
|
2013-01-01 23:15:01 +01:00
|
|
|
* Copyright (c) 2002-2013, PostgreSQL Global Development Group
|
2002-08-27 06:55:12 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/commands/prepare.h
|
2002-08-27 06:55:12 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PREPARE_H
|
|
|
|
#define PREPARE_H
|
|
|
|
|
2009-07-27 01:34:18 +02:00
|
|
|
#include "commands/explain.h"
|
2012-08-29 01:02:00 +02:00
|
|
|
#include "datatype/timestamp.h"
|
2007-03-13 01:33:44 +01:00
|
|
|
#include "utils/plancache.h"
|
2002-08-27 06:55:12 +02:00
|
|
|
|
2003-05-05 02:44:56 +02:00
|
|
|
/*
|
2007-03-13 01:33:44 +01:00
|
|
|
* The data structure representing a prepared statement. This is now just
|
|
|
|
* a thin veneer over a plancache entry --- the main addition is that of
|
|
|
|
* a name.
|
2003-05-05 02:44:56 +02:00
|
|
|
*
|
2007-03-13 01:33:44 +01:00
|
|
|
* Note: all subsidiary storage lives in the referenced plancache entry.
|
2003-05-05 02:44:56 +02:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* dynahash.c requires key to be first field */
|
2006-10-04 02:30:14 +02:00
|
|
|
char stmt_name[NAMEDATALEN];
|
2007-11-15 22:14:46 +01:00
|
|
|
CachedPlanSource *plansource; /* the actual cached plan */
|
2007-02-20 18:32:18 +01:00
|
|
|
bool from_sql; /* prepared via SQL, not FE/BE protocol? */
|
2006-10-04 02:30:14 +02:00
|
|
|
TimestampTz prepare_time; /* the time when the stmt was prepared */
|
2003-08-08 23:42:59 +02:00
|
|
|
} PreparedStatement;
|
2003-05-05 02:44:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */
|
2007-03-13 01:33:44 +01:00
|
|
|
extern void PrepareQuery(PrepareStmt *stmt, const char *queryString);
|
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
Making this operation look like a utility statement seems generally a good
idea, and particularly so in light of the desire to provide command
triggers for utility statements. The original choice of representing it as
SELECT with an IntoClause appendage had metastasized into rather a lot of
places, unfortunately, so that this patch is a great deal more complicated
than one might at first expect.
In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
subcommands required restructuring some EXPLAIN-related APIs. Add-on code
that calls ExplainOnePlan or ExplainOneUtility, or uses
ExplainOneQuery_hook, will need adjustment.
Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
which formerly were accepted though undocumented, are no longer accepted.
The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
The CREATE RULE case doesn't seem to have much real-world use (since the
rule would work only once before failing with "table already exists"),
so we'll not bother with that one.
Both SELECT INTO and CREATE TABLE AS still return a command tag of
"SELECT nnnn". There was some discussion of returning "CREATE TABLE nnnn",
but for the moment backwards compatibility wins the day.
Andres Freund and Tom Lane
2012-03-20 02:37:19 +01:00
|
|
|
extern void ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
|
|
|
|
const char *queryString, ParamListInfo params,
|
2006-10-04 02:30:14 +02:00
|
|
|
DestReceiver *dest, char *completionTag);
|
2002-08-27 06:55:12 +02:00
|
|
|
extern void DeallocateQuery(DeallocateStmt *stmt);
|
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
Making this operation look like a utility statement seems generally a good
idea, and particularly so in light of the desire to provide command
triggers for utility statements. The original choice of representing it as
SELECT with an IntoClause appendage had metastasized into rather a lot of
places, unfortunately, so that this patch is a great deal more complicated
than one might at first expect.
In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
subcommands required restructuring some EXPLAIN-related APIs. Add-on code
that calls ExplainOnePlan or ExplainOneUtility, or uses
ExplainOneQuery_hook, will need adjustment.
Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
which formerly were accepted though undocumented, are no longer accepted.
The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
The CREATE RULE case doesn't seem to have much real-world use (since the
rule would work only once before failing with "table already exists"),
so we'll not bother with that one.
Both SELECT INTO and CREATE TABLE AS still return a command tag of
"SELECT nnnn". There was some discussion of returning "CREATE TABLE nnnn",
but for the moment backwards compatibility wins the day.
Andres Freund and Tom Lane
2012-03-20 02:37:19 +01:00
|
|
|
extern void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into,
|
|
|
|
ExplainState *es,
|
2009-07-27 01:34:18 +02:00
|
|
|
const char *queryString, ParamListInfo params);
|
2002-08-27 06:55:12 +02:00
|
|
|
|
2003-05-05 02:44:56 +02:00
|
|
|
/* Low-level access to stored prepared statements */
|
|
|
|
extern void StorePreparedStatement(const char *stmt_name,
|
2011-09-16 06:42:53 +02:00
|
|
|
CachedPlanSource *plansource,
|
2006-01-08 08:00:27 +01:00
|
|
|
bool from_sql);
|
2003-05-05 02:44:56 +02:00
|
|
|
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
|
2003-08-04 02:43:34 +02:00
|
|
|
bool throwError);
|
2003-05-05 02:44:56 +02:00
|
|
|
extern void DropPreparedStatement(const char *stmt_name, bool showError);
|
2003-08-08 23:42:59 +02:00
|
|
|
extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt);
|
2005-06-22 19:45:46 +02:00
|
|
|
extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt);
|
2003-05-05 02:44:56 +02:00
|
|
|
|
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
Making this operation look like a utility statement seems generally a good
idea, and particularly so in light of the desire to provide command
triggers for utility statements. The original choice of representing it as
SELECT with an IntoClause appendage had metastasized into rather a lot of
places, unfortunately, so that this patch is a great deal more complicated
than one might at first expect.
In particular, keeping EXPLAIN working for SELECT INTO and CREATE TABLE AS
subcommands required restructuring some EXPLAIN-related APIs. Add-on code
that calls ExplainOnePlan or ExplainOneUtility, or uses
ExplainOneQuery_hook, will need adjustment.
Also, the cases PREPARE ... SELECT INTO and CREATE RULE ... SELECT INTO,
which formerly were accepted though undocumented, are no longer accepted.
The PREPARE case can be replaced with use of CREATE TABLE AS EXECUTE.
The CREATE RULE case doesn't seem to have much real-world use (since the
rule would work only once before failing with "table already exists"),
so we'll not bother with that one.
Both SELECT INTO and CREATE TABLE AS still return a command tag of
"SELECT nnnn". There was some discussion of returning "CREATE TABLE nnnn",
but for the moment backwards compatibility wins the day.
Andres Freund and Tom Lane
2012-03-20 02:37:19 +01:00
|
|
|
extern void DropAllPreparedStatements(void);
|
2007-04-12 08:53:49 +02:00
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
#endif /* PREPARE_H */
|