--- /dev/null
+
+
+
+
+ DISCARD
+ SQL - Language Statements
+
+
+
+ DISCARD
+ Discard internal server state
+
+
+
+
+
+
+
+DISCARD { ALL | PLANS | TEMPORARY | TEMP }
+
+
+
+
+
Description
+
+ DISCARD> releases internal resources associated with a
+ database session. These resources are normally released at the end
+ of the session.
+
+
+ DISCARD TEMP> drops all temporary tables created in the
+ current session. DISCARD PLANS> releases all internally
+ cached query plans. DISCARD ALL> resets a session to
+ its original state, discarding temporary resources and resetting
+ session-local configuration changes.
+
+
+
+
+
Parameters
+
+
+
+
+ TEMPORARY or TEMP
+
+ Drops all temporary tables created in the current session.
+
+
+
+
+
+ PLANS
+
+ Releases all cached query plans.
+
+
+
+
+
+ ALL
+
+ Releases all temporary resources associated with the current
+ session and resets the session to its initial state. This has
+ the same effect as executing the following sequence of
+ statements:
+SET SESSION AUTHORIZATION DEFAULT;
+RESET ALL;
+DEALLOCATE ALL;
+CLOSE ALL;
+UNLISTEN *;
+DISCARD PLANS;
+DISCARD TEMP;
+
+
+
+
+
+
+
+
+
+
Notes
+
+ DISCARD ALL> cannot be executed inside a transaction block.
+
+
+
+
+
Compatibility
+
+
DISCARD is a
PostgreSQL extension.
+
+
+
RESET configuration_parameter
RESET ALL
-RESET { PLANS | SESSION | TEMP | TEMPORARY }
See the SET> reference page for details on the
transaction behavior of RESET>.
-
- RESET> can also be used to release internal resources
- that are usually released at the end of session. RESET
- TEMP> drops all temporary tables created in the current session.
- RESET PLANS> releases all internally cached plans.
- RESET SESSION> releases all externally visible temporary
- resources associated with the current session.
-
-
-
- TEMP, TEMPORARY
-
- Drops all temporary tables created in the current session.
-
-
-
-
-
- PLANS
-
- Releases all cached query plans.
-
-
-
-
-
- SESSION
-
- Releases all temporary resources associated with the current
- session. This has the same effect as executing the following
- command sequence:
-SET SESSION AUTHORIZATION DEFAULT;
-RESET ALL;
-DEALLOCATE ALL;
-CLOSE ALL;
-UNLISTEN *;
-RESET PLANS;
-RESET TEMP;
-
-
-
-
-
-
-
Notes
-
- RESET SESSION> cannot be executed inside a transaction block.
-
-
-
Examples
-
+
Reference
&deallocate;
&declare;
&delete;
+ &discard;
&dropAggregate;
&dropCast;
&dropConversion;
# 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 $
#
#-------------------------------------------------------------------------
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 \
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * 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();
+}
* 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 $
*
*-------------------------------------------------------------------------
*/
return newnode;
}
+static DiscardStmt *
+_copyDiscardStmt(DiscardStmt *from)
+{
+ DiscardStmt *newnode = makeNode(DiscardStmt);
+
+ COPY_SCALAR_FIELD(target);
+
+ return newnode;
+}
+
static CreateTableSpaceStmt *
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
{
case T_VariableResetStmt:
retval = _copyVariableResetStmt(from);
break;
+ case T_DiscardStmt:
+ retval = _copyDiscardStmt(from);
+ break;
case T_CreateTableSpaceStmt:
retval = _copyCreateTableSpaceStmt(from);
break;
* 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 $
*
*-------------------------------------------------------------------------
*/
return true;
}
+static bool
+_equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
+{
+ COMPARE_SCALAR_FIELD(target);
+
+ return true;
+}
+
static bool
_equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *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;
*
*
* 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
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
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
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
| DeclareCursorStmt
| DefineStmt
| DeleteStmt
+ | DiscardStmt
| DropAssertStmt
| DropCastStmt
| DropGroupStmt
;
+/*****************************************************************************
+ *
+ * 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
| DELIMITER
| DELIMITERS
| DISABLE_P
+ | DISCARD
| DOCUMENT_P
| DOMAIN_P
| DOUBLE_P
| OWNER
| PARTIAL
| PASSWORD
+ | PLANS
| PREPARE
| PREPARED
| PRESERVE
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
{"delimiters", DELIMITERS},
{"desc", DESC},
{"disable", DISABLE_P},
+ {"discard", DISCARD},
{"distinct", DISTINCT},
{"do", DO},
{"document", DOCUMENT_P},
{"partial", PARTIAL},
{"password", PASSWORD},
{"placing", PLACING},
+ {"plans", PLANS},
{"position", POSITION},
{"precision", PRECISION},
{"prepare", PREPARE},
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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"
break;
case OBJECT_DOMAIN:
-
- /*
- * RemoveDomain does its own permissions checks
- */
+ /* RemoveDomain does its own permissions checks */
RemoveDomain(names, stmt->behavior,
stmt->missing_ok);
break;
break;
case OBJECT_SCHEMA:
-
- /*
- * RemoveSchema does its own permissions checks
- */
+ /* RemoveSchema does its own permissions checks */
RemoveSchema(names, stmt->behavior,
stmt->missing_ok);
break;
}
break;
+ case T_DiscardStmt:
+ DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
+ break;
+
case T_CreateTrigStmt:
CreateTrigger((CreateTrigStmt *) parsetree, InvalidOid);
break;
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;
* Written by Peter Eisentraut
.
*
* 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 $
*
*--------------------------------------------------------------------
*/
return tupdesc;
}
-/*
- * 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
*/
{
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,
* 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 $
*
*-------------------------------------------------------------------------
*/
/*
* Delete all declared cursors.
*
- * Used by commands: CLOSE ALL, RESET SESSION
+ * Used by commands: CLOSE ALL, DISCARD ALL
*/
void
PortalHashTableDeleteAll(void)
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.161 2007/04/08 00:26:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.162 2007/04/26 16:13:13 neilc Exp $
*/
/*----------------------------------------------------------------------
static const char *const sql_commands[] = {
"ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
"COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE",
- "DELETE FROM", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH", "GRANT",
- "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
+ "DELETE FROM", "DISCARD", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
+ "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
"REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
"SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TRUNCATE", "UNLISTEN",
"UPDATE", "VACUUM", NULL
}
/* XXX: implement tab completion for DELETE ... USING */
+/* DISCARD */
+ else if (pg_strcasecmp(prev_wd, "DISCARD") == 0)
+ {
+ static const char *const list_DISCARD[] =
+ {"ALL", "PLANS", "TEMP", NULL};
+
+ COMPLETE_WITH_LIST(list_DISCARD);
+ }
+
/* DROP (when not the previous word) */
/* DROP AGGREGATE */
else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * discard.h
+ * prototypes for discard.c.
+ *
+ *
+ * Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ *
+ * $PostgreSQL: pgsql/src/include/commands/discard.h,v 1.1 2007/04/26 16:13:13 neilc Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef DISCARD_H
+#define DISCARD_H
+
+#include "nodes/parsenodes.h"
+
+extern void DiscardCommand(DiscardStmt *stmt, bool isTopLevel);
+
+#endif /* DISCARD_H */
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.198 2007/04/02 03:49:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.199 2007/04/26 16:13:14 neilc Exp $
*
*-------------------------------------------------------------------------
*/
T_VariableSetStmt,
T_VariableShowStmt,
T_VariableResetStmt,
+ T_DiscardStmt,
T_CreateTrigStmt,
T_DropPropertyStmt,
T_CreatePLangStmt,
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.346 2007/04/16 01:14:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.347 2007/04/26 16:13:14 neilc Exp $
*
*-------------------------------------------------------------------------
*/
char *name;
} VariableResetStmt;
+/* ----------------------
+ * Discard Statement
+ * ----------------------
+ */
+
+typedef enum DiscardMode
+{
+ DISCARD_ALL,
+ DISCARD_PLANS,
+ DISCARD_TEMP
+} DiscardMode;
+
+typedef struct DiscardStmt
+{
+ NodeTag type;
+ DiscardMode target;
+} DiscardStmt;
+
/* ----------------------
* LOCK Statement
* ----------------------
(1 row)
--
--- Test RESET TEMP
+-- Test DISCARD TEMP
--
CREATE TEMP TABLE reset_test ( data text ) ON COMMIT DELETE ROWS;
SELECT relname FROM pg_class WHERE relname = 'reset_test';
reset_test
(1 row)
-RESET TEMP;
+DISCARD TEMP;
SELECT relname FROM pg_class WHERE relname = 'reset_test';
relname
---------
(0 rows)
--
--- Test RESET SESSION
+-- Test DISCARD ALL
--
-- do changes
DECLARE foo CURSOR WITH HOLD FOR SELECT 1;
t
(1 row)
--- big RESET
-RESET SESSION;
+-- discard everything
+DISCARD ALL;
-- look again
SELECT relname FROM pg_listener;
relname
SELECT '2006-08-13 12:34:56'::timestamptz;
--
--- Test RESET TEMP
+-- Test DISCARD TEMP
--
CREATE TEMP TABLE reset_test ( data text ) ON COMMIT DELETE ROWS;
SELECT relname FROM pg_class WHERE relname = 'reset_test';
-RESET TEMP;
+DISCARD TEMP;
SELECT relname FROM pg_class WHERE relname = 'reset_test';
--
--- Test RESET SESSION
+-- Test DISCARD ALL
--
-- do changes
SHOW vacuum_cost_delay;
SELECT relname from pg_class where relname = 'tmp_foo';
SELECT current_user = 'temp_reset_user';
--- big RESET
-RESET SESSION;
+-- discard everything
+DISCARD ALL;
-- look again
SELECT relname FROM pg_listener;
SELECT name FROM pg_prepared_statements;