Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "postgres.h"
00016
00017 #include "access/genam.h"
00018 #include "access/heapam.h"
00019 #include "access/htup_details.h"
00020 #include "access/sysattr.h"
00021 #include "catalog/dependency.h"
00022 #include "catalog/indexing.h"
00023 #include "catalog/namespace.h"
00024 #include "catalog/pg_rewrite.h"
00025 #include "miscadmin.h"
00026 #include "rewrite/rewriteRemove.h"
00027 #include "utils/acl.h"
00028 #include "utils/fmgroids.h"
00029 #include "utils/inval.h"
00030 #include "utils/lsyscache.h"
00031 #include "utils/syscache.h"
00032 #include "utils/tqual.h"
00033
00034
00035
00036
00037 void
00038 RemoveRewriteRuleById(Oid ruleOid)
00039 {
00040 Relation RewriteRelation;
00041 ScanKeyData skey[1];
00042 SysScanDesc rcscan;
00043 Relation event_relation;
00044 HeapTuple tuple;
00045 Oid eventRelationOid;
00046
00047
00048
00049
00050 RewriteRelation = heap_open(RewriteRelationId, RowExclusiveLock);
00051
00052
00053
00054
00055 ScanKeyInit(&skey[0],
00056 ObjectIdAttributeNumber,
00057 BTEqualStrategyNumber, F_OIDEQ,
00058 ObjectIdGetDatum(ruleOid));
00059
00060 rcscan = systable_beginscan(RewriteRelation, RewriteOidIndexId, true,
00061 SnapshotNow, 1, skey);
00062
00063 tuple = systable_getnext(rcscan);
00064
00065 if (!HeapTupleIsValid(tuple))
00066 elog(ERROR, "could not find tuple for rule %u", ruleOid);
00067
00068
00069
00070
00071
00072
00073 eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
00074 event_relation = heap_open(eventRelationOid, AccessExclusiveLock);
00075
00076
00077
00078
00079 simple_heap_delete(RewriteRelation, &tuple->t_self);
00080
00081 systable_endscan(rcscan);
00082
00083 heap_close(RewriteRelation, RowExclusiveLock);
00084
00085
00086
00087
00088
00089 CacheInvalidateRelcache(event_relation);
00090
00091
00092 heap_close(event_relation, NoLock);
00093 }