2007-04-26 18:13:15 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* discard.c
|
|
|
|
* The implementation of the DISCARD command
|
|
|
|
*
|
2020-01-01 18:21:45 +01:00
|
|
|
* Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
2007-04-26 18:13:15 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/commands/discard.c
|
2007-04-26 18:13:15 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/xact.h"
|
|
|
|
#include "catalog/namespace.h"
|
|
|
|
#include "commands/async.h"
|
|
|
|
#include "commands/discard.h"
|
|
|
|
#include "commands/prepare.h"
|
2013-10-03 22:17:18 +02:00
|
|
|
#include "commands/sequence.h"
|
2011-09-04 07:13:16 +02:00
|
|
|
#include "utils/guc.h"
|
2007-04-26 18:13:15 +02:00
|
|
|
#include "utils/portal.h"
|
|
|
|
|
|
|
|
static void DiscardAll(bool isTopLevel);
|
|
|
|
|
|
|
|
/*
|
2013-10-03 22:17:18 +02:00
|
|
|
* DISCARD { ALL | SEQUENCES | TEMP | PLANS }
|
2007-04-26 18:13:15 +02:00
|
|
|
*/
|
|
|
|
void
|
2007-11-15 23:25:18 +01:00
|
|
|
DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
|
2007-04-26 18:13:15 +02:00
|
|
|
{
|
|
|
|
switch (stmt->target)
|
|
|
|
{
|
|
|
|
case DISCARD_ALL:
|
|
|
|
DiscardAll(isTopLevel);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DISCARD_PLANS:
|
|
|
|
ResetPlanCache();
|
|
|
|
break;
|
|
|
|
|
2013-10-03 22:17:18 +02:00
|
|
|
case DISCARD_SEQUENCES:
|
|
|
|
ResetSequenceCaches();
|
|
|
|
break;
|
|
|
|
|
2007-04-26 18:13:15 +02:00
|
|
|
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
|
2007-11-15 22:14:46 +01:00
|
|
|
* 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.
|
2007-04-26 18:13:15 +02:00
|
|
|
*/
|
2018-02-17 02:44:15 +01:00
|
|
|
PreventInTransactionBlock(isTopLevel, "DISCARD ALL");
|
2007-04-26 18:13:15 +02:00
|
|
|
|
2011-02-27 19:43:29 +01:00
|
|
|
/* Closing portals might run user-defined code, so do that first. */
|
|
|
|
PortalHashTableDeleteAll();
|
2007-04-26 18:13:15 +02:00
|
|
|
SetPGVariable("session_authorization", NIL, false);
|
|
|
|
ResetAllOptions();
|
|
|
|
DropAllPreparedStatements();
|
|
|
|
Async_UnlistenAll();
|
2008-11-26 02:21:08 +01:00
|
|
|
LockReleaseAll(USER_LOCKMETHOD, true);
|
2007-04-26 18:13:15 +02:00
|
|
|
ResetPlanCache();
|
|
|
|
ResetTempTableNamespace();
|
2013-10-03 22:17:18 +02:00
|
|
|
ResetSequenceCaches();
|
2007-04-26 18:13:15 +02:00
|
|
|
}
|