LCOV - differential code coverage report
Current view: top level - src/backend/access/table - table.c (source / functions) Coverage Total Hit UBC GNC CBC DUB DCB
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 96.9 % 32 31 1 12 19 8
Current Date: 2026-03-14 14:10:32 -0400 Functions: 100.0 % 6 6 5 1 1
Baseline: lcov-20260315-024220-baseline Branches: 90.0 % 20 18 2 14 4 2 4
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 100.0 % 12 12 12
(360..) days: 95.0 % 20 19 1 19
Function coverage date bins:
(7,30] days: 100.0 % 1 1 1
(360..) days: 100.0 % 5 5 4 1
Branch coverage date bins:
(7,30] days: 100.0 % 14 14 14
(360..) days: 66.7 % 6 4 2 4

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * table.c
                                  4                 :                :  *    Generic routines for table related code.
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/backend/access/table/table.c
                                 12                 :                :  *
                                 13                 :                :  *
                                 14                 :                :  * NOTES
                                 15                 :                :  *    This file contains table_ routines that implement access to tables (in
                                 16                 :                :  *    contrast to other relation types like indexes) that are independent of
                                 17                 :                :  *    individual table access methods.
                                 18                 :                :  *
                                 19                 :                :  *-------------------------------------------------------------------------
                                 20                 :                :  */
                                 21                 :                : 
                                 22                 :                : #include "postgres.h"
                                 23                 :                : 
                                 24                 :                : #include "access/relation.h"
                                 25                 :                : #include "access/table.h"
                                 26                 :                : #include "utils/rel.h"
                                 27                 :                : 
                                 28                 :                : static inline void validate_relation_as_table(Relation r);
                                 29                 :                : 
                                 30                 :                : /* ----------------
                                 31                 :                :  *      table_open - open a table relation by relation OID
                                 32                 :                :  *
                                 33                 :                :  *      This is essentially relation_open plus check that the relation
                                 34                 :                :  *      is not an index nor a composite type.  (The caller should also
                                 35                 :                :  *      check that it's not a view or foreign table before assuming it has
                                 36                 :                :  *      storage.)
                                 37                 :                :  * ----------------
                                 38                 :                :  */
                                 39                 :                : Relation
 2610 andres@anarazel.de         40                 :CBC    10425885 : table_open(Oid relationId, LOCKMODE lockmode)
                                 41                 :                : {
                                 42                 :                :     Relation    r;
                                 43                 :                : 
                                 44                 :       10425885 :     r = relation_open(relationId, lockmode);
                                 45                 :                : 
   20 peter@eisentraut.org       46                 :GNC    10425881 :     validate_relation_as_table(r);
                                 47                 :                : 
 2020 michael@paquier.xyz        48                 :CBC    10425881 :     return r;
                                 49                 :                : }
                                 50                 :                : 
                                 51                 :                : 
                                 52                 :                : /* ----------------
                                 53                 :                :  *      try_table_open - open a table relation by relation OID
                                 54                 :                :  *
                                 55                 :                :  *      Same as table_open, except return NULL instead of failing
                                 56                 :                :  *      if the relation does not exist.
                                 57                 :                :  * ----------------
                                 58                 :                :  */
                                 59                 :                : Relation
                                 60                 :         167968 : try_table_open(Oid relationId, LOCKMODE lockmode)
                                 61                 :                : {
                                 62                 :                :     Relation    r;
                                 63                 :                : 
                                 64                 :         167968 :     r = try_relation_open(relationId, lockmode);
                                 65                 :                : 
                                 66                 :                :     /* leave if table does not exist */
                                 67         [ -  + ]:         167968 :     if (!r)
 2020 michael@paquier.xyz        68                 :UBC           0 :         return NULL;
                                 69                 :                : 
   20 peter@eisentraut.org       70                 :GNC      167968 :     validate_relation_as_table(r);
                                 71                 :                : 
 2610 andres@anarazel.de         72                 :CBC      167968 :     return r;
                                 73                 :                : }
                                 74                 :                : 
                                 75                 :                : /* ----------------
                                 76                 :                :  *      table_openrv - open a table relation specified
                                 77                 :                :  *      by a RangeVar node
                                 78                 :                :  *
                                 79                 :                :  *      As above, but relation is specified by a RangeVar.
                                 80                 :                :  * ----------------
                                 81                 :                :  */
                                 82                 :                : Relation
                                 83                 :          16755 : table_openrv(const RangeVar *relation, LOCKMODE lockmode)
                                 84                 :                : {
                                 85                 :                :     Relation    r;
                                 86                 :                : 
                                 87                 :          16755 :     r = relation_openrv(relation, lockmode);
                                 88                 :                : 
   20 peter@eisentraut.org       89                 :GNC       16739 :     validate_relation_as_table(r);
                                 90                 :                : 
 2610 andres@anarazel.de         91                 :CBC       16736 :     return r;
                                 92                 :                : }
                                 93                 :                : 
                                 94                 :                : /* ----------------
                                 95                 :                :  *      table_openrv_extended - open a table relation specified
                                 96                 :                :  *      by a RangeVar node
                                 97                 :                :  *
                                 98                 :                :  *      As above, but optionally return NULL instead of failing for
                                 99                 :                :  *      relation-not-found.
                                100                 :                :  * ----------------
                                101                 :                :  */
                                102                 :                : Relation
                                103                 :         262593 : table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode,
                                104                 :                :                       bool missing_ok)
                                105                 :                : {
                                106                 :                :     Relation    r;
                                107                 :                : 
                                108                 :         262593 :     r = relation_openrv_extended(relation, lockmode, missing_ok);
                                109                 :                : 
                                110         [ +  + ]:         262526 :     if (r)
   20 peter@eisentraut.org      111                 :GNC      262419 :         validate_relation_as_table(r);
                                112                 :                : 
 2610 andres@anarazel.de        113                 :CBC      262526 :     return r;
                                114                 :                : }
                                115                 :                : 
                                116                 :                : /* ----------------
                                117                 :                :  *      table_close - close a table
                                118                 :                :  *
                                119                 :                :  *      If lockmode is not "NoLock", we then release the specified lock.
                                120                 :                :  *
                                121                 :                :  *      Note that it is often sensible to hold a lock beyond relation_close;
                                122                 :                :  *      in that case, the lock is released automatically at xact end.
                                123                 :                :  *      ----------------
                                124                 :                :  */
                                125                 :                : void
                                126                 :       11475910 : table_close(Relation relation, LOCKMODE lockmode)
                                127                 :                : {
                                128                 :       11475910 :     relation_close(relation, lockmode);
                                129                 :       11475910 : }
                                130                 :                : 
                                131                 :                : /* ----------------
                                132                 :                :  *      validate_relation_as_table
                                133                 :                :  *
                                134                 :                :  *      Make sure relkind is table-like, that is, something that could be read
                                135                 :                :  *      from or written to directly in a query.
                                136                 :                :  * ----------------
                                137                 :                :  */
                                138                 :                : static inline void
   20 peter@eisentraut.org      139                 :GNC    10873007 : validate_relation_as_table(Relation r)
                                140                 :                : {
                                141         [ +  + ]:       10873007 :     if (r->rd_rel->relkind != RELKIND_RELATION &&
                                142         [ +  + ]:         183194 :         r->rd_rel->relkind != RELKIND_SEQUENCE &&
                                143         [ +  + ]:         183083 :         r->rd_rel->relkind != RELKIND_TOASTVALUE &&
                                144         [ +  + ]:         118200 :         r->rd_rel->relkind != RELKIND_VIEW &&
                                145         [ +  + ]:          90465 :         r->rd_rel->relkind != RELKIND_MATVIEW &&
                                146         [ +  + ]:          86606 :         r->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
                                147         [ +  + ]:          74761 :         r->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
 1328 akapila@postgresql.o      148         [ +  - ]:CBC           3 :         ereport(ERROR,
                                149                 :                :                 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
                                150                 :                :                  errmsg("cannot open relation \"%s\"",
                                151                 :                :                         RelationGetRelationName(r)),
                                152                 :                :                  errdetail_relkind_not_supported(r->rd_rel->relkind)));
                                153                 :       10873004 : }
        

Generated by: LCOV version 2.4-beta