summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2007-04-26 16:13:15 +0000
committerNeil Conway <neilc@samurai.com>2007-04-26 16:13:15 +0000
commit16efdb5ec7f28bed9541fc773330e3e2ebe2ed9a (patch)
tree6ec0d0c7b08584ef53bf340e4d71a156e9655eba /src/backend/commands
parent5ea27a4b2812d148f2516d130aee9dbaba45cedc (diff)
Rename the newly-added commands for discarding session state.
RESET SESSION, RESET PLANS, and RESET TEMP are now DISCARD ALL, DISCARD PLANS, and DISCARD TEMP, respectively. This is to avoid confusion with the pre-existing RESET variants: the DISCARD commands are not actually similar to RESET. Patch from Marko Kreen, with some minor editorialization.
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/Makefile4
-rw-r--r--src/backend/commands/discard.c71
2 files changed, 73 insertions, 2 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();
+}