LCOV - code coverage report
Current view: top level - src/backend/catalog - pg_range.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 45 49 91.8 %
Date: 2019-09-22 08:06:49 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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-2019, 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
      36          54 : RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
      37             :             Oid rangeSubOpclass, RegProcedure rangeCanonical,
      38             :             RegProcedure rangeSubDiff)
      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             : 
      47          54 :     pg_range = table_open(RangeRelationId, RowExclusiveLock);
      48             : 
      49          54 :     memset(nulls, 0, sizeof(nulls));
      50             : 
      51          54 :     values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
      52          54 :     values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
      53          54 :     values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
      54          54 :     values[Anum_pg_range_rngsubopc - 1] = ObjectIdGetDatum(rangeSubOpclass);
      55          54 :     values[Anum_pg_range_rngcanonical - 1] = ObjectIdGetDatum(rangeCanonical);
      56          54 :     values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
      57             : 
      58          54 :     tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
      59             : 
      60          54 :     CatalogTupleInsert(pg_range, tup);
      61          54 :     heap_freetuple(tup);
      62             : 
      63             :     /* record type's dependencies on range-related items */
      64             : 
      65          54 :     myself.classId = TypeRelationId;
      66          54 :     myself.objectId = rangeTypeOid;
      67          54 :     myself.objectSubId = 0;
      68             : 
      69          54 :     referenced.classId = TypeRelationId;
      70          54 :     referenced.objectId = rangeSubType;
      71          54 :     referenced.objectSubId = 0;
      72          54 :     recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      73             : 
      74          54 :     referenced.classId = OperatorClassRelationId;
      75          54 :     referenced.objectId = rangeSubOpclass;
      76          54 :     referenced.objectSubId = 0;
      77          54 :     recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      78             : 
      79          54 :     if (OidIsValid(rangeCollation))
      80             :     {
      81          16 :         referenced.classId = CollationRelationId;
      82          16 :         referenced.objectId = rangeCollation;
      83          16 :         referenced.objectSubId = 0;
      84          16 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      85             :     }
      86             : 
      87          54 :     if (OidIsValid(rangeCanonical))
      88             :     {
      89           0 :         referenced.classId = ProcedureRelationId;
      90           0 :         referenced.objectId = rangeCanonical;
      91           0 :         referenced.objectSubId = 0;
      92           0 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      93             :     }
      94             : 
      95          54 :     if (OidIsValid(rangeSubDiff))
      96             :     {
      97           6 :         referenced.classId = ProcedureRelationId;
      98           6 :         referenced.objectId = rangeSubDiff;
      99           6 :         referenced.objectSubId = 0;
     100           6 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
     101             :     }
     102             : 
     103          54 :     table_close(pg_range, RowExclusiveLock);
     104          54 : }
     105             : 
     106             : 
     107             : /*
     108             :  * RangeDelete
     109             :  *      Remove the pg_range entry for the specified type.
     110             :  */
     111             : void
     112          24 : RangeDelete(Oid rangeTypeOid)
     113             : {
     114             :     Relation    pg_range;
     115             :     ScanKeyData key[1];
     116             :     SysScanDesc scan;
     117             :     HeapTuple   tup;
     118             : 
     119          24 :     pg_range = table_open(RangeRelationId, RowExclusiveLock);
     120             : 
     121          24 :     ScanKeyInit(&key[0],
     122             :                 Anum_pg_range_rngtypid,
     123             :                 BTEqualStrategyNumber, F_OIDEQ,
     124             :                 ObjectIdGetDatum(rangeTypeOid));
     125             : 
     126          24 :     scan = systable_beginscan(pg_range, RangeTypidIndexId, true,
     127             :                               NULL, 1, key);
     128             : 
     129          72 :     while (HeapTupleIsValid(tup = systable_getnext(scan)))
     130             :     {
     131          24 :         CatalogTupleDelete(pg_range, &tup->t_self);
     132             :     }
     133             : 
     134          24 :     systable_endscan(scan);
     135             : 
     136          24 :     table_close(pg_range, RowExclusiveLock);
     137          24 : }

Generated by: LCOV version 1.13