LCOV - differential code coverage report
Current view: top level - src/backend/rewrite - rewriteSupport.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 96.2 % 26 25 1 25
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 3 3 3
Baseline: 16@8cea358b128 Branches: 64.3 % 14 9 5 9
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: 96.2 % 26 25 1 25
Function coverage date bins:
(240..) days: 100.0 % 3 3 3
Branch coverage date bins:
(240..) days: 64.3 % 14 9 5 9

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * rewriteSupport.c
                                  4                 :                :  *
                                  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/rewriteSupport.c
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include "access/htup_details.h"
                                 18                 :                : #include "access/table.h"
                                 19                 :                : #include "catalog/indexing.h"
                                 20                 :                : #include "catalog/pg_class.h"
                                 21                 :                : #include "catalog/pg_rewrite.h"
                                 22                 :                : #include "rewrite/rewriteSupport.h"
                                 23                 :                : #include "utils/inval.h"
                                 24                 :                : #include "utils/lsyscache.h"
                                 25                 :                : #include "utils/syscache.h"
                                 26                 :                : 
                                 27                 :                : 
                                 28                 :                : /*
                                 29                 :                :  * Is there a rule by the given name?
                                 30                 :                :  */
                                 31                 :                : bool
 8032 tgl@sss.pgh.pa.us          32                 :CBC          13 : IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
                                 33                 :                : {
 5173 rhaas@postgresql.org       34                 :             13 :     return SearchSysCacheExists2(RULERELNAME,
                                 35                 :                :                                  ObjectIdGetDatum(owningRel),
                                 36                 :                :                                  PointerGetDatum(ruleName));
                                 37                 :                : }
                                 38                 :                : 
                                 39                 :                : 
                                 40                 :                : /*
                                 41                 :                :  * SetRelationRuleStatus
                                 42                 :                :  *      Set the value of the relation's relhasrules field in pg_class.
                                 43                 :                :  *
                                 44                 :                :  * NOTE: caller must be holding an appropriate lock on the relation.
                                 45                 :                :  *
                                 46                 :                :  * NOTE: an important side-effect of this operation is that an SI invalidation
                                 47                 :                :  * message is sent out to all backends --- including me --- causing relcache
                                 48                 :                :  * entries to be flushed or updated with the new set of rules for the table.
                                 49                 :                :  * This must happen even if we find that no change is needed in the pg_class
                                 50                 :                :  * row.
                                 51                 :                :  */
                                 52                 :                : void
 4060 tgl@sss.pgh.pa.us          53                 :           7342 : SetRelationRuleStatus(Oid relationId, bool relHasRules)
                                 54                 :                : {
                                 55                 :                :     Relation    relationRelation;
                                 56                 :                :     HeapTuple   tuple;
                                 57                 :                :     Form_pg_class classForm;
                                 58                 :                : 
                                 59                 :                :     /*
                                 60                 :                :      * Find the tuple to update in pg_class, using syscache for the lookup.
                                 61                 :                :      */
 1910 andres@anarazel.de         62                 :           7342 :     relationRelation = table_open(RelationRelationId, RowExclusiveLock);
 5173 rhaas@postgresql.org       63                 :           7342 :     tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relationId));
 8550 tgl@sss.pgh.pa.us          64         [ -  + ]:           7342 :     if (!HeapTupleIsValid(tuple))
 7569 tgl@sss.pgh.pa.us          65         [ #  # ]:UBC           0 :         elog(ERROR, "cache lookup failed for relation %u", relationId);
 7947 tgl@sss.pgh.pa.us          66                 :CBC        7342 :     classForm = (Form_pg_class) GETSTRUCT(tuple);
                                 67                 :                : 
 4060                            68         [ +  + ]:           7342 :     if (classForm->relhasrules != relHasRules)
                                 69                 :                :     {
                                 70                 :                :         /* Do the update */
 7947                            71                 :           6880 :         classForm->relhasrules = relHasRules;
                                 72                 :                : 
 2630 alvherre@alvh.no-ip.       73                 :           6880 :         CatalogTupleUpdate(relationRelation, &tuple->t_self, tuple);
                                 74                 :                :     }
                                 75                 :                :     else
                                 76                 :                :     {
                                 77                 :                :         /* no need to change tuple, but force relcache rebuild anyway */
 7369 tgl@sss.pgh.pa.us          78                 :            462 :         CacheInvalidateRelcacheByTuple(tuple);
                                 79                 :                :     }
                                 80                 :                : 
 8886 JanWieck@Yahoo.com         81                 :           7342 :     heap_freetuple(tuple);
 1910 andres@anarazel.de         82                 :           7342 :     table_close(relationRelation, RowExclusiveLock);
10141 scrappy@hub.org            83                 :           7342 : }
                                 84                 :                : 
                                 85                 :                : /*
                                 86                 :                :  * Find rule oid.
                                 87                 :                :  *
                                 88                 :                :  * If missing_ok is false, throw an error if rule name not found.  If
                                 89                 :                :  * true, just return InvalidOid.
                                 90                 :                :  */
                                 91                 :                : Oid
 5001 rhaas@postgresql.org       92                 :            107 : get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
                                 93                 :                : {
                                 94                 :                :     HeapTuple   tuple;
                                 95                 :                :     Form_pg_rewrite ruleform;
                                 96                 :                :     Oid         ruleoid;
                                 97                 :                : 
                                 98                 :                :     /* Find the rule's pg_rewrite tuple, get its OID */
                                 99                 :            107 :     tuple = SearchSysCache2(RULERELNAME,
                                100                 :                :                             ObjectIdGetDatum(relid),
                                101                 :                :                             PointerGetDatum(rulename));
                                102         [ +  + ]:            107 :     if (!HeapTupleIsValid(tuple))
                                103                 :                :     {
                                104         [ +  + ]:              9 :         if (missing_ok)
                                105                 :              3 :             return InvalidOid;
                                106         [ +  - ]:              6 :         ereport(ERROR,
                                107                 :                :                 (errcode(ERRCODE_UNDEFINED_OBJECT),
                                108                 :                :                  errmsg("rule \"%s\" for relation \"%s\" does not exist",
                                109                 :                :                         rulename, get_rel_name(relid))));
                                110                 :                :     }
 1972 andres@anarazel.de        111                 :             98 :     ruleform = (Form_pg_rewrite) GETSTRUCT(tuple);
                                112         [ -  + ]:             98 :     Assert(relid == ruleform->ev_class);
                                113                 :             98 :     ruleoid = ruleform->oid;
 5001 rhaas@postgresql.org      114                 :             98 :     ReleaseSysCache(tuple);
                                115                 :             98 :     return ruleoid;
                                116                 :                : }
        

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