LCOV - differential code coverage report
Current view: top level - src/backend/commands - discard.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 93.1 % 29 27 2 27
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 2 2 2
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*-------------------------------------------------------------------------
       2                 :  *
       3                 :  * discard.c
       4                 :  *    The implementation of the DISCARD command
       5                 :  *
       6                 :  * Copyright (c) 1996-2023, 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 CBC          15 : DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
      32                 : {
      33              15 :     switch (stmt->target)
      34                 :     {
      35               3 :         case DISCARD_ALL:
      36               3 :             DiscardAll(isTopLevel);
      37               3 :             break;
      38                 : 
      39               2 :         case DISCARD_PLANS:
      40               2 :             ResetPlanCache();
      41               2 :             break;
      42                 : 
      43               6 :         case DISCARD_SEQUENCES:
      44               6 :             ResetSequenceCaches();
      45               6 :             break;
      46                 : 
      47               4 :         case DISCARD_TEMP:
      48               4 :             ResetTempTableNamespace();
      49               4 :             break;
      50                 : 
      51 UBC           0 :         default:
      52               0 :             elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
      53                 :     }
      54 CBC          15 : }
      55                 : 
      56                 : static void
      57               3 : 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               3 :     PreventInTransactionBlock(isTopLevel, "DISCARD ALL");
      67                 : 
      68                 :     /* Closing portals might run user-defined code, so do that first. */
      69               3 :     PortalHashTableDeleteAll();
      70               3 :     SetPGVariable("session_authorization", NIL, false);
      71               3 :     ResetAllOptions();
      72               3 :     DropAllPreparedStatements();
      73               3 :     Async_UnlistenAll();
      74               3 :     LockReleaseAll(USER_LOCKMETHOD, true);
      75               3 :     ResetPlanCache();
      76               3 :     ResetTempTableNamespace();
      77               3 :     ResetSequenceCaches();
      78               3 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a