diff options
author | vvvv <vvvv@yandex-team.com> | 2024-11-07 12:29:36 +0300 |
---|---|---|
committer | vvvv <vvvv@yandex-team.com> | 2024-11-07 13:49:47 +0300 |
commit | d4c258e9431675bab6745c8638df6e3dfd4dca6b (patch) | |
tree | b5efcfa11351152a4c872fccaea35749141c0b11 /yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c | |
parent | 13a4f274caef5cfdaf0263b24e4d6bdd5521472b (diff) | |
download | ydb-d4c258e9431675bab6745c8638df6e3dfd4dca6b.tar.gz |
Moved other yql/essentials libs YQL-19206
init
commit_hash:7d4c435602078407bbf20dd3c32f9c90d2bbcbc0
Diffstat (limited to 'yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c')
-rw-r--r-- | yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c new file mode 100644 index 00000000000..296dc82d2ee --- /dev/null +++ b/yql/essentials/parser/pg_wrapper/postgresql/src/backend/commands/discard.c @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------- + * + * discard.c + * The implementation of the DISCARD command + * + * Copyright (c) 1996-2023, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/backend/commands/discard.c + * + *------------------------------------------------------------------------- + */ +#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/sequence.h" +#include "utils/guc.h" +#include "utils/portal.h" + +static void DiscardAll(bool isTopLevel); + +/* + * DISCARD { ALL | SEQUENCES | TEMP | PLANS } + */ +void +DiscardCommand(DiscardStmt *stmt, bool isTopLevel) +{ + switch (stmt->target) + { + case DISCARD_ALL: + DiscardAll(isTopLevel); + break; + + case DISCARD_PLANS: + ResetPlanCache(); + break; + + case DISCARD_SEQUENCES: + ResetSequenceCaches(); + 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. + */ + PreventInTransactionBlock(isTopLevel, "DISCARD ALL"); + + /* Closing portals might run user-defined code, so do that first. */ + PortalHashTableDeleteAll(); + SetPGVariable("session_authorization", NIL, false); + ResetAllOptions(); + DropAllPreparedStatements(); + Async_UnlistenAll(); + LockReleaseAll(USER_LOCKMETHOD, true); + ResetPlanCache(); + ResetTempTableNamespace(); + ResetSequenceCaches(); +} |