00001 /*------------------------------------------------------------------------- 00002 * 00003 * discard.c 00004 * The implementation of the DISCARD command 00005 * 00006 * Copyright (c) 1996-2013, PostgreSQL Global Development Group 00007 * 00008 * 00009 * IDENTIFICATION 00010 * src/backend/commands/discard.c 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #include "postgres.h" 00015 00016 #include "access/xact.h" 00017 #include "catalog/namespace.h" 00018 #include "commands/async.h" 00019 #include "commands/discard.h" 00020 #include "commands/prepare.h" 00021 #include "utils/guc.h" 00022 #include "utils/portal.h" 00023 00024 static void DiscardAll(bool isTopLevel); 00025 00026 /* 00027 * DISCARD { ALL | TEMP | PLANS } 00028 */ 00029 void 00030 DiscardCommand(DiscardStmt *stmt, bool isTopLevel) 00031 { 00032 switch (stmt->target) 00033 { 00034 case DISCARD_ALL: 00035 DiscardAll(isTopLevel); 00036 break; 00037 00038 case DISCARD_PLANS: 00039 ResetPlanCache(); 00040 break; 00041 00042 case DISCARD_TEMP: 00043 ResetTempTableNamespace(); 00044 break; 00045 00046 default: 00047 elog(ERROR, "unrecognized DISCARD target: %d", stmt->target); 00048 } 00049 } 00050 00051 static void 00052 DiscardAll(bool isTopLevel) 00053 { 00054 /* 00055 * Disallow DISCARD ALL in a transaction block. This is arguably 00056 * inconsistent (we don't make a similar check in the command sequence 00057 * that DISCARD ALL is equivalent to), but the idea is to catch mistakes: 00058 * DISCARD ALL inside a transaction block would leave the transaction 00059 * still uncommitted. 00060 */ 00061 PreventTransactionChain(isTopLevel, "DISCARD ALL"); 00062 00063 /* Closing portals might run user-defined code, so do that first. */ 00064 PortalHashTableDeleteAll(); 00065 SetPGVariable("session_authorization", NIL, false); 00066 ResetAllOptions(); 00067 DropAllPreparedStatements(); 00068 Async_UnlistenAll(); 00069 LockReleaseAll(USER_LOCKMETHOD, true); 00070 ResetPlanCache(); 00071 ResetTempTableNamespace(); 00072 }