LCOV - differential code coverage report
Current view: top level - src/backend/catalog - pg_range.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 95.6 % 45 43 2 43
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 2 2 2
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 95.6 % 45 43 2 43
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 2 2 2

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * pg_range.c
                                  4                 :  *    routines to support manipulation of the pg_range relation
                                  5                 :  *
                                  6                 :  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
                                  7                 :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :  *
                                  9                 :  *
                                 10                 :  * IDENTIFICATION
                                 11                 :  *    src/backend/catalog/pg_range.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/dependency.h"
                                 21                 : #include "catalog/indexing.h"
                                 22                 : #include "catalog/pg_collation.h"
                                 23                 : #include "catalog/pg_opclass.h"
                                 24                 : #include "catalog/pg_proc.h"
                                 25                 : #include "catalog/pg_range.h"
                                 26                 : #include "catalog/pg_type.h"
                                 27                 : #include "utils/fmgroids.h"
                                 28                 : #include "utils/rel.h"
                                 29                 : 
                                 30                 : 
                                 31                 : /*
                                 32                 :  * RangeCreate
                                 33                 :  *      Create an entry in pg_range.
                                 34                 :  */
                                 35                 : void
 4175 heikki.linnakangas         36 CBC          64 : RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
                                 37                 :             Oid rangeSubOpclass, RegProcedure rangeCanonical,
                                 38                 :             RegProcedure rangeSubDiff, Oid multirangeTypeOid)
                                 39                 : {
                                 40                 :     Relation    pg_range;
                                 41                 :     Datum       values[Natts_pg_range];
                                 42                 :     bool        nulls[Natts_pg_range];
                                 43                 :     HeapTuple   tup;
                                 44                 :     ObjectAddress myself;
                                 45                 :     ObjectAddress referenced;
                                 46                 :     ObjectAddress referencing;
                                 47                 :     ObjectAddresses *addrs;
                                 48                 : 
 1539 andres                     49              64 :     pg_range = table_open(RangeRelationId, RowExclusiveLock);
                                 50                 : 
 4164 tgl                        51              64 :     memset(nulls, 0, sizeof(nulls));
                                 52                 : 
      bruce                      53              64 :     values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
                                 54              64 :     values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
 4175 heikki.linnakangas         55              64 :     values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
 4164 bruce                      56              64 :     values[Anum_pg_range_rngsubopc - 1] = ObjectIdGetDatum(rangeSubOpclass);
 4175 heikki.linnakangas         57              64 :     values[Anum_pg_range_rngcanonical - 1] = ObjectIdGetDatum(rangeCanonical);
 4164 bruce                      58              64 :     values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
  840 akorotkov                  59              64 :     values[Anum_pg_range_rngmultitypid - 1] = ObjectIdGetDatum(multirangeTypeOid);
                                 60                 : 
 4175 heikki.linnakangas         61              64 :     tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
                                 62                 : 
 2259 alvherre                   63              64 :     CatalogTupleInsert(pg_range, tup);
 4175 heikki.linnakangas         64              64 :     heap_freetuple(tup);
                                 65                 : 
                                 66                 :     /* record type's dependencies on range-related items */
  946 michael                    67              64 :     addrs = new_object_addresses();
                                 68                 : 
                                 69              64 :     ObjectAddressSet(myself, TypeRelationId, rangeTypeOid);
                                 70                 : 
                                 71              64 :     ObjectAddressSet(referenced, TypeRelationId, rangeSubType);
                                 72              64 :     add_exact_object_address(&referenced, addrs);
                                 73                 : 
                                 74              64 :     ObjectAddressSet(referenced, OperatorClassRelationId, rangeSubOpclass);
                                 75              64 :     add_exact_object_address(&referenced, addrs);
                                 76                 : 
 4175 heikki.linnakangas         77              64 :     if (OidIsValid(rangeCollation))
                                 78                 :     {
  946 michael                    79              29 :         ObjectAddressSet(referenced, CollationRelationId, rangeCollation);
                                 80              29 :         add_exact_object_address(&referenced, addrs);
                                 81                 :     }
                                 82                 : 
 4175 heikki.linnakangas         83              64 :     if (OidIsValid(rangeCanonical))
                                 84                 :     {
  946 michael                    85 UBC           0 :         ObjectAddressSet(referenced, ProcedureRelationId, rangeCanonical);
                                 86               0 :         add_exact_object_address(&referenced, addrs);
                                 87                 :     }
                                 88                 : 
 4175 heikki.linnakangas         89 CBC          64 :     if (OidIsValid(rangeSubDiff))
                                 90                 :     {
  946 michael                    91               4 :         ObjectAddressSet(referenced, ProcedureRelationId, rangeSubDiff);
                                 92               4 :         add_exact_object_address(&referenced, addrs);
                                 93                 :     }
                                 94                 : 
                                 95              64 :     record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
                                 96              64 :     free_object_addresses(addrs);
                                 97                 : 
                                 98                 :     /* record multirange type's dependency on the range type */
  840 akorotkov                  99              64 :     referencing.classId = TypeRelationId;
                                100              64 :     referencing.objectId = multirangeTypeOid;
                                101              64 :     referencing.objectSubId = 0;
                                102              64 :     recordDependencyOn(&referencing, &myself, DEPENDENCY_INTERNAL);
                                103                 : 
 1539 andres                    104              64 :     table_close(pg_range, RowExclusiveLock);
 4175 heikki.linnakangas        105              64 : }
                                106                 : 
                                107                 : 
                                108                 : /*
                                109                 :  * RangeDelete
                                110                 :  *      Remove the pg_range entry for the specified type.
                                111                 :  */
                                112                 : void
                                113              45 : RangeDelete(Oid rangeTypeOid)
                                114                 : {
                                115                 :     Relation    pg_range;
                                116                 :     ScanKeyData key[1];
                                117                 :     SysScanDesc scan;
                                118                 :     HeapTuple   tup;
                                119                 : 
 1539 andres                    120              45 :     pg_range = table_open(RangeRelationId, RowExclusiveLock);
                                121                 : 
 4175 heikki.linnakangas        122              45 :     ScanKeyInit(&key[0],
                                123                 :                 Anum_pg_range_rngtypid,
                                124                 :                 BTEqualStrategyNumber, F_OIDEQ,
                                125                 :                 ObjectIdGetDatum(rangeTypeOid));
                                126                 : 
                                127              45 :     scan = systable_beginscan(pg_range, RangeTypidIndexId, true,
                                128                 :                               NULL, 1, key);
                                129                 : 
                                130              90 :     while (HeapTupleIsValid(tup = systable_getnext(scan)))
                                131                 :     {
 2258 tgl                       132              45 :         CatalogTupleDelete(pg_range, &tup->t_self);
                                133                 :     }
                                134                 : 
 4175 heikki.linnakangas        135              45 :     systable_endscan(scan);
                                136                 : 
 1539 andres                    137              45 :     table_close(pg_range, RowExclusiveLock);
 4175 heikki.linnakangas        138              45 : }
        

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