Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/Makefile4
-rw-r--r--src/backend/commands/discard.c71
-rw-r--r--src/backend/nodes/copyfuncs.c15
-rw-r--r--src/backend/nodes/equalfuncs.c13
-rw-r--r--src/backend/parser/gram.y45
-rw-r--r--src/backend/parser/keywords.c4
-rw-r--r--src/backend/tcop/utility.c39
-rw-r--r--src/backend/utils/misc/guc.c33
-rw-r--r--src/backend/utils/mmgr/portalmem.c4
9 files changed, 170 insertions, 58 deletions
diff --git a/src/backend/commands/Makefile b/src/backend/commands/Makefile
index f2e5bf52f20..4b25ae6489e 100644
--- a/src/backend/commands/Makefile
+++ b/src/backend/commands/Makefile
@@ -4,7 +4,7 @@
# Makefile for backend/commands
#
# IDENTIFICATION
-# $PostgreSQL: pgsql/src/backend/commands/Makefile,v 1.35 2007/01/20 17:16:11 petere Exp $
+# $PostgreSQL: pgsql/src/backend/commands/Makefile,v 1.36 2007/04/26 16:13:09 neilc Exp $
#
#-------------------------------------------------------------------------
@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
OBJS = aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \
conversioncmds.o copy.o \
- dbcommands.o define.o explain.o functioncmds.o \
+ dbcommands.o define.o discard.o explain.o functioncmds.o \
indexcmds.o lockcmds.o operatorcmds.o opclasscmds.o \
portalcmds.o prepare.o proclang.o \
schemacmds.o sequence.o tablecmds.o tablespace.o trigger.o \
diff --git a/src/backend/commands/discard.c b/src/backend/commands/discard.c
new file mode 100644
index 00000000000..d2ae6defd04
--- /dev/null
+++ b/src/backend/commands/discard.c
@@ -0,0 +1,71 @@
+/*-------------------------------------------------------------------------
+ *
+ * discard.c
+ * The implementation of the DISCARD command
+ *
+ * Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ *
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgsql/src/backend/commands/discard.c,v 1.1 2007/04/26 16:13:10 neilc Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "access/xact.h"
+#include "catalog/namespace.h"
+#include "commands/async.h"
+#include "commands/discard.h"
+#include "commands/prepare.h"
+#include "commands/variable.h"
+#include "utils/plancache.h"
+#include "utils/portal.h"
+
+static void DiscardAll(bool isTopLevel);
+
+/*
+ * DISCARD { ALL | TEMP | PLANS }
+ */
+void
+DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
+{
+ switch (stmt->target)
+ {
+ case DISCARD_ALL:
+ DiscardAll(isTopLevel);
+ break;
+
+ case DISCARD_PLANS:
+ ResetPlanCache();
+ break;
+
+ case DISCARD_TEMP:
+ ResetTempTableNamespace();
+ break;
+
+ default:
+ elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
+ }
+}
+
+static void
+DiscardAll(bool isTopLevel)
+{
+ /*
+ * Disallow DISCARD ALL in a transaction block. This is arguably
+ * inconsistent (we don't make a similar check in the command
+ * sequence that DISCARD ALL is equivalent to), but the idea is
+ * to catch mistakes: DISCARD ALL inside a transaction block
+ * would leave the transaction still uncommitted.
+ */
+ PreventTransactionChain(isTopLevel, "DISCARD ALL");
+
+ SetPGVariable("session_authorization", NIL, false);
+ ResetAllOptions();
+ DropAllPreparedStatements();
+ PortalHashTableDeleteAll();
+ Async_UnlistenAll();
+ ResetPlanCache();
+ ResetTempTableNamespace();
+}
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 9bf57fb87f2..988120a9634 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.373 2007/04/02 03:49:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.374 2007/04/26 16:13:10 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2589,6 +2589,16 @@ _copyVariableResetStmt(VariableResetStmt *from)
return newnode;
}
+static DiscardStmt *
+_copyDiscardStmt(DiscardStmt *from)
+{
+ DiscardStmt *newnode = makeNode(DiscardStmt);
+
+ COPY_SCALAR_FIELD(target);
+
+ return newnode;
+}
+
static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
{
@@ -3380,6 +3390,9 @@ copyObject(void *from)
case T_VariableResetStmt:
retval = _copyVariableResetStmt(from);
break;
+ case T_DiscardStmt:
+ retval = _copyDiscardStmt(from);
+ break;
case T_CreateTableSpaceStmt:
retval = _copyCreateTableSpaceStmt(from);
break;
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 1cc0c343dca..c1500948dca 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.304 2007/04/02 03:49:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.305 2007/04/26 16:13:11 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1377,6 +1377,14 @@ _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
}
static bool
+_equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
+{
+ COMPARE_SCALAR_FIELD(target);
+
+ return true;
+}
+
+static bool
_equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
{
COMPARE_STRING_FIELD(tablespacename);
@@ -2313,6 +2321,9 @@ equal(void *a, void *b)
case T_VariableResetStmt:
retval = _equalVariableResetStmt(a, b);
break;
+ case T_DiscardStmt:
+ retval = _equalDiscardStmt(a, b);
+ break;
case T_CreateTableSpaceStmt:
retval = _equalCreateTableSpaceStmt(a, b);
break;
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index b9728deaada..a69e6989a94 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.589 2007/04/16 01:14:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.590 2007/04/26 16:13:11 neilc Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -158,7 +158,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
CreateAssertStmt CreateTrigStmt CreateUserStmt CreateRoleStmt
- CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt
+ CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt
DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
DropUserStmt DropdbStmt DropTableSpaceStmt ExplainStmt FetchStmt
@@ -382,7 +382,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS
- DESC DISABLE_P DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
+ DESC DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EXCEPT EXCLUDING
EXCLUSIVE EXECUTE EXISTS EXPLAIN EXTERNAL EXTRACT
@@ -416,7 +416,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
- PARTIAL PASSWORD PLACING POSITION
+ PARTIAL PASSWORD PLACING PLANS POSITION
PRECISION PRESERVE PREPARE PREPARED PRIMARY
PRIOR PRIVILEGES PROCEDURAL PROCEDURE
@@ -569,6 +569,7 @@ stmt :
| DeclareCursorStmt
| DefineStmt
| DeleteStmt
+ | DiscardStmt
| DropAssertStmt
| DropCastStmt
| DropGroupStmt
@@ -1330,6 +1331,40 @@ CheckPointStmt:
/*****************************************************************************
*
+ * DISCARD { ALL | TEMP | PLANS }
+ *
+ *****************************************************************************/
+
+DiscardStmt:
+ DISCARD ALL
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_ALL;
+ $$ = (Node *) n;
+ }
+ | DISCARD TEMP
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_TEMP;
+ $$ = (Node *) n;
+ }
+ | DISCARD TEMPORARY
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_TEMP;
+ $$ = (Node *) n;
+ }
+ | DISCARD PLANS
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_PLANS;
+ $$ = (Node *) n;
+ }
+ ;
+
+
+/*****************************************************************************
+ *
* ALTER [ TABLE | INDEX ] variations
*
*****************************************************************************/
@@ -8796,6 +8831,7 @@ unreserved_keyword:
| DELIMITER
| DELIMITERS
| DISABLE_P
+ | DISCARD
| DOCUMENT_P
| DOMAIN_P
| DOUBLE_P
@@ -8881,6 +8917,7 @@ unreserved_keyword:
| OWNER
| PARTIAL
| PASSWORD
+ | PLANS
| PREPARE
| PREPARED
| PRESERVE
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
index 9f6cf1e20e4..5c8ef10a214 100644
--- a/src/backend/parser/keywords.c
+++ b/src/backend/parser/keywords.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.186 2007/04/02 03:49:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.187 2007/04/26 16:13:12 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -124,6 +124,7 @@ static const ScanKeyword ScanKeywords[] = {
{"delimiters", DELIMITERS},
{"desc", DESC},
{"disable", DISABLE_P},
+ {"discard", DISCARD},
{"distinct", DISTINCT},
{"do", DO},
{"document", DOCUMENT_P},
@@ -269,6 +270,7 @@ static const ScanKeyword ScanKeywords[] = {
{"partial", PARTIAL},
{"password", PASSWORD},
{"placing", PLACING},
+ {"plans", PLANS},
{"position", POSITION},
{"precision", PRECISION},
{"prepare", PREPARE},
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 88adb625d55..9dd700ffe70 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.277 2007/04/12 06:53:47 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.278 2007/04/26 16:13:12 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,7 @@
#include "commands/copy.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
+#include "commands/discard.h"
#include "commands/explain.h"
#include "commands/lockcmds.h"
#include "commands/portalcmds.h"
@@ -604,10 +605,7 @@ ProcessUtility(Node *parsetree,
break;
case OBJECT_DOMAIN:
-
- /*
- * RemoveDomain does its own permissions checks
- */
+ /* RemoveDomain does its own permissions checks */
RemoveDomain(names, stmt->behavior,
stmt->missing_ok);
break;
@@ -618,10 +616,7 @@ ProcessUtility(Node *parsetree,
break;
case OBJECT_SCHEMA:
-
- /*
- * RemoveSchema does its own permissions checks
- */
+ /* RemoveSchema does its own permissions checks */
RemoveSchema(names, stmt->behavior,
stmt->missing_ok);
break;
@@ -994,6 +989,10 @@ ProcessUtility(Node *parsetree,
}
break;
+ case T_DiscardStmt:
+ DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
+ break;
+
case T_CreateTrigStmt:
CreateTrigger((CreateTrigStmt *) parsetree, InvalidOid);
break;
@@ -1752,12 +1751,22 @@ CreateCommandTag(Node *parsetree)
break;
case T_VariableResetStmt:
- {
- VariableResetStmt *stmt = (VariableResetStmt *) parsetree;
- if (pg_strcasecmp(stmt->name, "session") == 0)
- tag = "RESET SESSION";
- else
- tag = "RESET";
+ tag = "RESET";
+ break;
+
+ case T_DiscardStmt:
+ switch (((DiscardStmt *) parsetree)->target) {
+ case DISCARD_ALL:
+ tag = "DISCARD ALL";
+ break;
+ case DISCARD_PLANS:
+ tag = "DISCARD PLANS";
+ break;
+ case DISCARD_TEMP:
+ tag = "DISCARD TEMP";
+ break;
+ default:
+ tag = "???";
}
break;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 9b1e813dc6c..a3a8f79a5d1 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.388 2007/04/22 03:52:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.389 2007/04/26 16:13:12 neilc Exp $
*
*--------------------------------------------------------------------
*/
@@ -5048,30 +5048,6 @@ GetPGVariableResultDesc(const char *name)
}
/*
- * RESET SESSION command.
- */
-static void
-ResetSession(bool isTopLevel)
-{
- /*
- * Disallow RESET SESSION in a transaction block. This is arguably
- * inconsistent (we don't make a similar check in the command
- * sequence that RESET SESSION is equivalent to), but the idea is
- * to catch mistakes: RESET SESSION inside a transaction block
- * would leave the transaction still uncommitted.
- */
- PreventTransactionChain(isTopLevel, "RESET SESSION");
-
- SetPGVariable("session_authorization", NIL, false);
- ResetAllOptions();
- DropAllPreparedStatements();
- PortalHashTableDeleteAll();
- Async_UnlistenAll();
- ResetPlanCache();
- ResetTempTableNamespace();
-}
-
-/*
* RESET command
*/
void
@@ -5079,13 +5055,6 @@ ResetPGVariable(const char *name, bool isTopLevel)
{
if (pg_strcasecmp(name, "all") == 0)
ResetAllOptions();
- else if (pg_strcasecmp(name, "session") == 0)
- ResetSession(isTopLevel);
- else if (pg_strcasecmp(name, "temp") == 0 ||
- pg_strcasecmp(name, "temporary") == 0)
- ResetTempTableNamespace();
- else if (pg_strcasecmp(name, "plans") == 0)
- ResetPlanCache();
else
set_config_option(name,
NULL,
diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index eeba207dc94..69bb3e3ebdb 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.101 2007/04/12 06:53:48 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.102 2007/04/26 16:13:13 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -455,7 +455,7 @@ PortalDrop(Portal portal, bool isTopCommit)
/*
* Delete all declared cursors.
*
- * Used by commands: CLOSE ALL, RESET SESSION
+ * Used by commands: CLOSE ALL, DISCARD ALL
*/
void
PortalHashTableDeleteAll(void)