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

Go to the source code of this file.

Macros

#define ViewSelectRuleName   "_RETURN"
 

Functions

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.

Function Documentation

◆ get_rewrite_oid()

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

Definition at line 92 of file rewriteSupport.c.

93{
94 HeapTuple tuple;
95 Form_pg_rewrite ruleform;
96 Oid ruleoid;
97
98 /* Find the rule's pg_rewrite tuple, get its OID */
99 tuple = SearchSysCache2(RULERELNAME,
100 ObjectIdGetDatum(relid),
101 PointerGetDatum(rulename));
102 if (!HeapTupleIsValid(tuple))
103 {
104 if (missing_ok)
105 return InvalidOid;
107 (errcode(ERRCODE_UNDEFINED_OBJECT),
108 errmsg("rule \"%s\" for relation \"%s\" does not exist",
109 rulename, get_rel_name(relid))));
110 }
111 ruleform = (Form_pg_rewrite) GETSTRUCT(tuple);
112 Assert(relid == ruleform->ev_class);
113 ruleoid = ruleform->oid;
114 ReleaseSysCache(tuple);
115 return ruleoid;
116}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
char * get_rel_name(Oid relid)
Definition: lsyscache.c:2068
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
#define InvalidOid
Definition: postgres_ext.h:35
unsigned int Oid
Definition: postgres_ext.h:30
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:232

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

Referenced by get_object_address_relobject().

◆ IsDefinedRewriteRule()

bool IsDefinedRewriteRule ( Oid  owningRel,
const char *  ruleName 
)

Definition at line 32 of file rewriteSupport.c.

33{
34 return SearchSysCacheExists2(RULERELNAME,
35 ObjectIdGetDatum(owningRel),
36 PointerGetDatum(ruleName));
37}
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:102

References ObjectIdGetDatum(), PointerGetDatum(), and SearchSysCacheExists2.

Referenced by RenameRewriteRule().

◆ SetRelationRuleStatus()

void SetRelationRuleStatus ( Oid  relationId,
bool  relHasRules 
)

Definition at line 53 of file rewriteSupport.c.

54{
55 Relation relationRelation;
56 HeapTuple tuple;
57 Form_pg_class classForm;
58
59 /*
60 * Find the tuple to update in pg_class, using syscache for the lookup.
61 */
62 relationRelation = table_open(RelationRelationId, RowExclusiveLock);
63 tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relationId));
64 if (!HeapTupleIsValid(tuple))
65 elog(ERROR, "cache lookup failed for relation %u", relationId);
66 classForm = (Form_pg_class) GETSTRUCT(tuple);
67
68 if (classForm->relhasrules != relHasRules)
69 {
70 /* Do the update */
71 classForm->relhasrules = relHasRules;
72
73 CatalogTupleUpdate(relationRelation, &tuple->t_self, tuple);
74 }
75 else
76 {
77 /* no need to change tuple, but force relcache rebuild anyway */
79 }
80
81 heap_freetuple(tuple);
82 table_close(relationRelation, RowExclusiveLock);
83}
#define elog(elevel,...)
Definition: elog.h:225
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
Definition: inval.c:1665
#define RowExclusiveLock
Definition: lockdefs.h:38
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:91
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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

Referenced by DefineQueryRewrite().