LCOV - differential code coverage report
Current view: top level - src/backend/rewrite - rewriteRemove.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 94.1 % 17 16 1 16
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 1 1 1
Baseline: 16@8cea358b128 Branches: 60.0 % 10 6 4 6
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 94.1 % 17 16 1 16
Function coverage date bins:
(240..) days: 100.0 % 1 1 1
Branch coverage date bins:
(240..) days: 60.0 % 10 6 4 6

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * rewriteRemove.c
                                  4                 :                :  *    routines for removing rewrite rules
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/backend/rewrite/rewriteRemove.c
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include "access/genam.h"
                                 18                 :                : #include "access/htup_details.h"
                                 19                 :                : #include "access/table.h"
                                 20                 :                : #include "catalog/catalog.h"
                                 21                 :                : #include "catalog/indexing.h"
                                 22                 :                : #include "catalog/pg_rewrite.h"
                                 23                 :                : #include "miscadmin.h"
                                 24                 :                : #include "rewrite/rewriteRemove.h"
                                 25                 :                : #include "utils/fmgroids.h"
                                 26                 :                : #include "utils/inval.h"
                                 27                 :                : #include "utils/rel.h"
                                 28                 :                : 
                                 29                 :                : /*
                                 30                 :                :  * Guts of rule deletion.
                                 31                 :                :  */
                                 32                 :                : void
 7947 tgl@sss.pgh.pa.us          33                 :CBC        1382 : RemoveRewriteRuleById(Oid ruleOid)
                                 34                 :                : {
                                 35                 :                :     Relation    RewriteRelation;
                                 36                 :                :     ScanKeyData skey[1];
                                 37                 :                :     SysScanDesc rcscan;
                                 38                 :                :     Relation    event_relation;
                                 39                 :                :     HeapTuple   tuple;
                                 40                 :                :     Oid         eventRelationOid;
                                 41                 :                : 
                                 42                 :                :     /*
                                 43                 :                :      * Open the pg_rewrite relation.
                                 44                 :                :      */
 1910 andres@anarazel.de         45                 :           1382 :     RewriteRelation = table_open(RewriteRelationId, RowExclusiveLock);
                                 46                 :                : 
                                 47                 :                :     /*
                                 48                 :                :      * Find the tuple for the target rule.
                                 49                 :                :      */
 7459 tgl@sss.pgh.pa.us          50                 :           1382 :     ScanKeyInit(&skey[0],
                                 51                 :                :                 Anum_pg_rewrite_oid,
                                 52                 :                :                 BTEqualStrategyNumber, F_OIDEQ,
                                 53                 :                :                 ObjectIdGetDatum(ruleOid));
                                 54                 :                : 
 6940                            55                 :           1382 :     rcscan = systable_beginscan(RewriteRelation, RewriteOidIndexId, true,
                                 56                 :                :                                 NULL, 1, skey);
                                 57                 :                : 
 7947                            58                 :           1382 :     tuple = systable_getnext(rcscan);
                                 59                 :                : 
                                 60         [ -  + ]:           1382 :     if (!HeapTupleIsValid(tuple))
 7569 tgl@sss.pgh.pa.us          61         [ #  # ]:UBC           0 :         elog(ERROR, "could not find tuple for rule %u", ruleOid);
                                 62                 :                : 
                                 63                 :                :     /*
                                 64                 :                :      * We had better grab AccessExclusiveLock to ensure that no queries are
                                 65                 :                :      * going on that might depend on this rule.  (Note: a weaker lock would
                                 66                 :                :      * suffice if it's not an ON SELECT rule.)
                                 67                 :                :      */
 7947 tgl@sss.pgh.pa.us          68                 :CBC        1382 :     eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
 1910 andres@anarazel.de         69                 :           1382 :     event_relation = table_open(eventRelationOid, AccessExclusiveLock);
                                 70                 :                : 
 1577 peter@eisentraut.org       71   [ +  +  +  + ]:           1382 :     if (!allowSystemTableMods && IsSystemRelation(event_relation))
                                 72         [ +  - ]:              1 :         ereport(ERROR,
                                 73                 :                :                 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                                 74                 :                :                  errmsg("permission denied: \"%s\" is a system catalog",
                                 75                 :                :                         RelationGetRelationName(event_relation))));
                                 76                 :                : 
                                 77                 :                :     /*
                                 78                 :                :      * Now delete the pg_rewrite tuple for the rule
                                 79                 :                :      */
 2629 tgl@sss.pgh.pa.us          80                 :           1381 :     CatalogTupleDelete(RewriteRelation, &tuple->t_self);
                                 81                 :                : 
 7947                            82                 :           1381 :     systable_endscan(rcscan);
                                 83                 :                : 
 1910 andres@anarazel.de         84                 :           1381 :     table_close(RewriteRelation, RowExclusiveLock);
                                 85                 :                : 
                                 86                 :                :     /*
                                 87                 :                :      * Issue shared-inval notice to force all backends (including me!) to
                                 88                 :                :      * update relcache entries with the new rule set.
                                 89                 :                :      */
 5634 tgl@sss.pgh.pa.us          90                 :           1381 :     CacheInvalidateRelcache(event_relation);
                                 91                 :                : 
                                 92                 :                :     /* Close rel, but keep lock till commit... */
 1910 andres@anarazel.de         93                 :           1381 :     table_close(event_relation, NoLock);
10141 scrappy@hub.org            94                 :           1381 : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622