PostgreSQL Source Code  git master
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

◆ ViewSelectRuleName

#define ViewSelectRuleName   "_RETURN"

Definition at line 18 of file rewriteSupport.h.

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

Function Documentation

◆ get_rewrite_oid()

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

Definition at line 93 of file rewriteSupport.c.

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

Referenced by get_object_address_relobject().

94 {
95  HeapTuple tuple;
96  Form_pg_rewrite ruleform;
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  ruleform = (Form_pg_rewrite) GETSTRUCT(tuple);
113  Assert(relid == ruleform->ev_class);
114  ruleoid = ruleform->oid;
115  ReleaseSysCache(tuple);
116  return ruleoid;
117 }
Definition: htup_details.h:654
#define PointerGetDatum(X)
Definition: postgres.h:600
int errcode(int sqlerrcode)
Definition: elog.c:698
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1138
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
int errmsg(const char *fmt,...)
Definition: elog.c:909
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1899

◆ IsDefinedRewriteRule()

bool IsDefinedRewriteRule ( Oid  owningRel,
const char *  ruleName 

Definition at line 33 of file rewriteSupport.c.

References ObjectIdGetDatum, PointerGetDatum, RULERELNAME, and SearchSysCacheExists2.

Referenced by RenameRewriteRule().

34 {
36  ObjectIdGetDatum(owningRel),
37  PointerGetDatum(ruleName));
38 }
#define PointerGetDatum(X)
Definition: postgres.h:600
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:186

◆ SetRelationRuleStatus()

void SetRelationRuleStatus ( Oid  relationId,
bool  relHasRules 

Definition at line 54 of file rewriteSupport.c.

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

Referenced by DefineQueryRewrite().

55 {
56  Relation relationRelation;
57  HeapTuple tuple;
58  Form_pg_class classForm;
60  /*
61  * Find the tuple to update in pg_class, using syscache for the lookup.
62  */
63  relationRelation = table_open(RelationRelationId, RowExclusiveLock);
64  tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relationId));
65  if (!HeapTupleIsValid(tuple))
66  elog(ERROR, "cache lookup failed for relation %u", relationId);
67  classForm = (Form_pg_class) GETSTRUCT(tuple);
69  if (classForm->relhasrules != relHasRules)
70  {
71  /* Do the update */
72  classForm->relhasrules = relHasRules;
74  CatalogTupleUpdate(relationRelation, &tuple->t_self, tuple);
75  }
76  else
77  {
78  /* no need to change tuple, but force relcache rebuild anyway */
80  }
82  heap_freetuple(tuple);
83  table_close(relationRelation, RowExclusiveLock);
84 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Definition: htup_details.h:654
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
FormData_pg_class * Form_pg_class
Definition: pg_class.h:153
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:175
#define elog(elevel,...)
Definition: elog.h:232
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
Definition: inval.c:1378
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39