LCOV - code coverage report
Current view: top level - src/backend/catalog - pg_range.c (source / functions) Hit Total Coverage
Test: PostgreSQL Lines: 45 49 91.8 %
Date: 2017-09-29 13:40:31 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-2017, 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/heapam.h"
      19             : #include "access/htup_details.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             : #include "utils/tqual.h"
      30             : 
      31             : 
      32             : /*
      33             :  * RangeCreate
      34             :  *      Create an entry in pg_range.
      35             :  */
      36             : void
      37           9 : RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
      38             :             Oid rangeSubOpclass, RegProcedure rangeCanonical,
      39             :             RegProcedure rangeSubDiff)
      40             : {
      41             :     Relation    pg_range;
      42             :     Datum       values[Natts_pg_range];
      43             :     bool        nulls[Natts_pg_range];
      44             :     HeapTuple   tup;
      45             :     ObjectAddress myself;
      46             :     ObjectAddress referenced;
      47             : 
      48           9 :     pg_range = heap_open(RangeRelationId, RowExclusiveLock);
      49             : 
      50           9 :     memset(nulls, 0, sizeof(nulls));
      51             : 
      52           9 :     values[Anum_pg_range_rngtypid - 1] = ObjectIdGetDatum(rangeTypeOid);
      53           9 :     values[Anum_pg_range_rngsubtype - 1] = ObjectIdGetDatum(rangeSubType);
      54           9 :     values[Anum_pg_range_rngcollation - 1] = ObjectIdGetDatum(rangeCollation);
      55           9 :     values[Anum_pg_range_rngsubopc - 1] = ObjectIdGetDatum(rangeSubOpclass);
      56           9 :     values[Anum_pg_range_rngcanonical - 1] = ObjectIdGetDatum(rangeCanonical);
      57           9 :     values[Anum_pg_range_rngsubdiff - 1] = ObjectIdGetDatum(rangeSubDiff);
      58             : 
      59           9 :     tup = heap_form_tuple(RelationGetDescr(pg_range), values, nulls);
      60             : 
      61           9 :     CatalogTupleInsert(pg_range, tup);
      62           9 :     heap_freetuple(tup);
      63             : 
      64             :     /* record type's dependencies on range-related items */
      65             : 
      66           9 :     myself.classId = TypeRelationId;
      67           9 :     myself.objectId = rangeTypeOid;
      68           9 :     myself.objectSubId = 0;
      69             : 
      70           9 :     referenced.classId = TypeRelationId;
      71           9 :     referenced.objectId = rangeSubType;
      72           9 :     referenced.objectSubId = 0;
      73           9 :     recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      74             : 
      75           9 :     referenced.classId = OperatorClassRelationId;
      76           9 :     referenced.objectId = rangeSubOpclass;
      77           9 :     referenced.objectSubId = 0;
      78           9 :     recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      79             : 
      80           9 :     if (OidIsValid(rangeCollation))
      81             :     {
      82           3 :         referenced.classId = CollationRelationId;
      83           3 :         referenced.objectId = rangeCollation;
      84           3 :         referenced.objectSubId = 0;
      85           3 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      86             :     }
      87             : 
      88           9 :     if (OidIsValid(rangeCanonical))
      89             :     {
      90           0 :         referenced.classId = ProcedureRelationId;
      91           0 :         referenced.objectId = rangeCanonical;
      92           0 :         referenced.objectSubId = 0;
      93           0 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
      94             :     }
      95             : 
      96           9 :     if (OidIsValid(rangeSubDiff))
      97             :     {
      98           1 :         referenced.classId = ProcedureRelationId;
      99           1 :         referenced.objectId = rangeSubDiff;
     100           1 :         referenced.objectSubId = 0;
     101           1 :         recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
     102             :     }
     103             : 
     104           9 :     heap_close(pg_range, RowExclusiveLock);
     105           9 : }
     106             : 
     107             : 
     108             : /*
     109             :  * RangeDelete
     110             :  *      Remove the pg_range entry for the specified type.
     111             :  */
     112             : void
     113           6 : RangeDelete(Oid rangeTypeOid)
     114             : {
     115             :     Relation    pg_range;
     116             :     ScanKeyData key[1];
     117             :     SysScanDesc scan;
     118             :     HeapTuple   tup;
     119             : 
     120           6 :     pg_range = heap_open(RangeRelationId, RowExclusiveLock);
     121             : 
     122           6 :     ScanKeyInit(&key[0],
     123             :                 Anum_pg_range_rngtypid,
     124             :                 BTEqualStrategyNumber, F_OIDEQ,
     125             :                 ObjectIdGetDatum(rangeTypeOid));
     126             : 
     127           6 :     scan = systable_beginscan(pg_range, RangeTypidIndexId, true,
     128             :                               NULL, 1, key);
     129             : 
     130          18 :     while (HeapTupleIsValid(tup = systable_getnext(scan)))
     131             :     {
     132           6 :         CatalogTupleDelete(pg_range, &tup->t_self);
     133             :     }
     134             : 
     135           6 :     systable_endscan(scan);
     136             : 
     137           6 :     heap_close(pg_range, RowExclusiveLock);
     138           6 : }

Generated by: LCOV version 1.11