PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
rewriteRemove.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_rewrite.h"
#include "miscadmin.h"
#include "rewrite/rewriteRemove.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
Include dependency graph for rewriteRemove.c:

Go to the source code of this file.


void RemoveRewriteRuleById (Oid ruleOid)

Function Documentation

void RemoveRewriteRuleById ( Oid  ruleOid)

Definition at line 38 of file rewriteRemove.c.

References AccessExclusiveLock, BTEqualStrategyNumber, CacheInvalidateRelcache(), CatalogTupleDelete(), elog, ERROR, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, NoLock, NULL, ObjectIdAttributeNumber, ObjectIdGetDatum, RewriteOidIndexId, RewriteRelationId, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by doDeletion().

39 {
40  Relation RewriteRelation;
41  ScanKeyData skey[1];
42  SysScanDesc rcscan;
43  Relation event_relation;
44  HeapTuple tuple;
45  Oid eventRelationOid;
47  /*
48  * Open the pg_rewrite relation.
49  */
50  RewriteRelation = heap_open(RewriteRelationId, RowExclusiveLock);
52  /*
53  * Find the tuple for the target rule.
54  */
55  ScanKeyInit(&skey[0],
57  BTEqualStrategyNumber, F_OIDEQ,
58  ObjectIdGetDatum(ruleOid));
60  rcscan = systable_beginscan(RewriteRelation, RewriteOidIndexId, true,
61  NULL, 1, skey);
63  tuple = systable_getnext(rcscan);
65  if (!HeapTupleIsValid(tuple))
66  elog(ERROR, "could not find tuple for rule %u", ruleOid);
68  /*
69  * We had better grab AccessExclusiveLock to ensure that no queries are
70  * going on that might depend on this rule. (Note: a weaker lock would
71  * suffice if it's not an ON SELECT rule.)
72  */
73  eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
74  event_relation = heap_open(eventRelationOid, AccessExclusiveLock);
76  /*
77  * Now delete the pg_rewrite tuple for the rule
78  */
79  CatalogTupleDelete(RewriteRelation, &tuple->t_self);
81  systable_endscan(rcscan);
83  heap_close(RewriteRelation, RowExclusiveLock);
85  /*
86  * Issue shared-inval notice to force all backends (including me!) to
87  * update relcache entries with the new rule set.
88  */
89  CacheInvalidateRelcache(event_relation);
91  /* Close rel, but keep lock till commit... */
92  heap_close(event_relation, NoLock);
93 }
#define RewriteOidIndexId
Definition: indexing.h:214
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
Definition: htup_details.h:656
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define RewriteRelationId
Definition: pg_rewrite.h:32
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:53
void CacheInvalidateRelcache(Relation relation)
Definition: inval.c:1225
#define AccessExclusiveLock
Definition: lockdefs.h:46
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define elog
Definition: elog.h:219
#define BTEqualStrategyNumber
Definition: stratnum.h:31