PostgreSQL Source Code  git master
discard.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * discard.c
4  * The implementation of the DISCARD command
5  *
6  * Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  *
8  *
9  * IDENTIFICATION
10  * src/backend/commands/discard.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include "access/xact.h"
17 #include "catalog/namespace.h"
18 #include "commands/async.h"
19 #include "commands/discard.h"
20 #include "commands/prepare.h"
21 #include "commands/sequence.h"
22 #include "utils/guc.h"
23 #include "utils/portal.h"
24 
25 static void DiscardAll(bool isTopLevel);
26 
27 /*
28  * DISCARD { ALL | SEQUENCES | TEMP | PLANS }
29  */
30 void
31 DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
32 {
33  switch (stmt->target)
34  {
35  case DISCARD_ALL:
36  DiscardAll(isTopLevel);
37  break;
38 
39  case DISCARD_PLANS:
41  break;
42 
43  case DISCARD_SEQUENCES:
45  break;
46 
47  case DISCARD_TEMP:
49  break;
50 
51  default:
52  elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
53  }
54 }
55 
56 static void
57 DiscardAll(bool isTopLevel)
58 {
59  /*
60  * Disallow DISCARD ALL in a transaction block. This is arguably
61  * inconsistent (we don't make a similar check in the command sequence
62  * that DISCARD ALL is equivalent to), but the idea is to catch mistakes:
63  * DISCARD ALL inside a transaction block would leave the transaction
64  * still uncommitted.
65  */
66  PreventInTransactionBlock(isTopLevel, "DISCARD ALL");
67 
68  /* Closing portals might run user-defined code, so do that first. */
70  SetPGVariable("session_authorization", NIL, false);
78 }
void Async_UnlistenAll(void)
Definition: async.c:770
void DropAllPreparedStatements(void)
Definition: prepare.c:537
void ResetSequenceCaches(void)
Definition: sequence.c:1864
static void DiscardAll(bool isTopLevel)
Definition: discard.c:57
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
void ResetAllOptions(void)
Definition: guc.c:2005
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc_funcs.c:315
#define stmt
Definition: indent_codes.h:59
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
Definition: lock.c:2147
#define USER_LOCKMETHOD
Definition: lock.h:126
void ResetTempTableNamespace(void)
Definition: namespace.c:4629
@ DISCARD_ALL
Definition: parsenodes.h:3938
@ DISCARD_PLANS
Definition: parsenodes.h:3939
@ DISCARD_SEQUENCES
Definition: parsenodes.h:3940
@ DISCARD_TEMP
Definition: parsenodes.h:3941
#define NIL
Definition: pg_list.h:68
void ResetPlanCache(void)
Definition: plancache.c:2187
void PortalHashTableDeleteAll(void)
Definition: portalmem.c:607
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3584