1/*-------------------------------------------------------------------------
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/rewrite/rewriteSupport.c
13 *-------------------------------------------------------------------------
29 * Is there a rule by the given name?
41 * SetRelationRuleStatus
42 * Set the value of the relation's relhasrules field in pg_class.
44 * NOTE: caller must be holding an appropriate lock on the relation.
46 * NOTE: an important side-effect of this operation is that an SI invalidation
47 * message is sent out to all backends --- including me --- causing relcache
48 * entries to be flushed or updated with the new set of rules for the table.
49 * This must happen even if we find that no change is needed in the pg_class
60 * Find the tuple to update in pg_class, using syscache for the lookup.
65 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
68 if (classForm->relhasrules != relHasRules)
71 classForm->relhasrules = relHasRules;
77 /* no need to change tuple, but force relcache rebuild anyway */
88 * If missing_ok is false, throw an error if rule name not found. If
89 * true, just return InvalidOid.
98 /* Find the rule's pg_rewrite tuple, get its OID */
107 (
errcode(ERRCODE_UNDEFINED_OBJECT),
108 errmsg(
"rule \"%s\" for relation \"%s\" does not exist",
112 Assert(relid == ruleform->ev_class);
113 ruleoid = ruleform->oid;
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
char * get_rel_name(Oid relid)
FormData_pg_class * Form_pg_class
FormData_pg_rewrite * Form_pg_rewrite
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
void SetRelationRuleStatus(Oid relationId, bool relHasRules)
bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists2(cacheId, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)