PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
rewriteSupport.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


#define ViewSelectRuleName   "_RETURN"


bool IsDefinedRewriteRule (Oid owningRel, const char *ruleName)
void SetRelationRuleStatus (Oid relationId, bool relHasRules)
Oid get_rewrite_oid (Oid relid, const char *rulename, bool missing_ok)

Macro Definition Documentation

#define ViewSelectRuleName   "_RETURN"

Definition at line 18 of file rewriteSupport.h.

Referenced by DefineQueryRewrite(), DefineViewRules(), and pg_get_viewdef_worker().

Function Documentation

Oid get_rewrite_oid ( Oid  relid,
const char *  rulename,
bool  missing_ok 

Definition at line 94 of file rewriteSupport.c.

References Assert, ereport, errcode(), errmsg(), ERROR, get_rel_name(), GETSTRUCT, HeapTupleGetOid, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, PointerGetDatum, ReleaseSysCache(), RULERELNAME, and SearchSysCache2.

Referenced by get_object_address_relobject().

95 {
96  HeapTuple tuple;
97  Oid ruleoid;
99  /* Find the rule's pg_rewrite tuple, get its OID */
101  ObjectIdGetDatum(relid),
102  PointerGetDatum(rulename));
103  if (!HeapTupleIsValid(tuple))
104  {
105  if (missing_ok)
106  return InvalidOid;
107  ereport(ERROR,
109  errmsg("rule \"%s\" for relation \"%s\" does not exist",
110  rulename, get_rel_name(relid))));
111  }
112  Assert(relid == ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class);
113  ruleoid = HeapTupleGetOid(tuple);
114  ReleaseSysCache(tuple);
115  return ruleoid;
116 }
Definition: htup_details.h:656
#define PointerGetDatum(X)
Definition: postgres.h:562
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:675
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:53
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
#define SearchSysCache2(cacheId, key1, key2)
Definition: syscache.h:158
bool IsDefinedRewriteRule ( Oid  owningRel,
const char *  ruleName 

Definition at line 34 of file rewriteSupport.c.

References ObjectIdGetDatum, PointerGetDatum, RULERELNAME, and SearchSysCacheExists2.

Referenced by RenameRewriteRule().

35 {
37  ObjectIdGetDatum(owningRel),
38  PointerGetDatum(ruleName));
39 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:176
void SetRelationRuleStatus ( Oid  relationId,
bool  relHasRules 

Definition at line 55 of file rewriteSupport.c.

References CacheInvalidateRelcacheByTuple(), CatalogTupleUpdate(), elog, ERROR, GETSTRUCT, heap_close, heap_freetuple(), heap_open(), HeapTupleIsValid, ObjectIdGetDatum, RelationRelationId, RELOID, RowExclusiveLock, SearchSysCacheCopy1, and HeapTupleData::t_self.

Referenced by DefineQueryRewrite().

56 {
57  Relation relationRelation;
58  HeapTuple tuple;
59  Form_pg_class classForm;
61  /*
62  * Find the tuple to update in pg_class, using syscache for the lookup.
63  */
64  relationRelation = heap_open(RelationRelationId, RowExclusiveLock);
65  tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relationId));
66  if (!HeapTupleIsValid(tuple))
67  elog(ERROR, "cache lookup failed for relation %u", relationId);
68  classForm = (Form_pg_class) GETSTRUCT(tuple);
70  if (classForm->relhasrules != relHasRules)
71  {
72  /* Do the update */
73  classForm->relhasrules = relHasRules;
75  CatalogTupleUpdate(relationRelation, &tuple->t_self, tuple);
76  }
77  else
78  {
79  /* no need to change tuple, but force relcache rebuild anyway */
81  }
83  heap_freetuple(tuple);
84  heap_close(relationRelation, RowExclusiveLock);
85 }
Definition: htup_details.h:656
#define RelationRelationId
Definition: pg_class.h:29
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
Definition: inval.c:1269
#define elog
Definition: elog.h:219