1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00
Files
postgres/src/backend/rewrite/rewriteRemove.c
Peter Eisentraut dbbca2cf29 Remove unused #include's from backend .c files
as determined by include-what-you-use (IWYU)

While IWYU also suggests to *add* a bunch of #include's (which is its
main purpose), this patch does not do that.  In some cases, a more
specific #include replaces another less specific one.

Some manual adjustments of the automatic result:

- IWYU currently doesn't know about includes that provide global
  variable declarations (like -Wmissing-variable-declarations), so
  those includes are being kept manually.

- All includes for port(ability) headers are being kept for now, to
  play it safe.

- No changes of catalog/pg_foo.h to catalog/pg_foo_d.h, to keep the
  patch from exploding in size.

Note that this patch touches just *.c files, so nothing declared in
header files changes in hidden ways.

As a small example, in src/backend/access/transam/rmgr.c, some IWYU
pragma annotations are added to handle a special case there.

Discussion: https://www.postgresql.org/message-id/flat/af837490-6b2f-46df-ba05-37ea6a6653fc%40eisentraut.org
2024-03-04 12:02:20 +01:00

95 lines
2.5 KiB
C

/*-------------------------------------------------------------------------
*
* rewriteRemove.c
* routines for removing rewrite rules
*
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/rewrite/rewriteRemove.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/pg_rewrite.h"
#include "miscadmin.h"
#include "rewrite/rewriteRemove.h"
#include "utils/fmgroids.h"
#include "utils/inval.h"
#include "utils/rel.h"
/*
* Guts of rule deletion.
*/
void
RemoveRewriteRuleById(Oid ruleOid)
{
Relation RewriteRelation;
ScanKeyData skey[1];
SysScanDesc rcscan;
Relation event_relation;
HeapTuple tuple;
Oid eventRelationOid;
/*
* Open the pg_rewrite relation.
*/
RewriteRelation = table_open(RewriteRelationId, RowExclusiveLock);
/*
* Find the tuple for the target rule.
*/
ScanKeyInit(&skey[0],
Anum_pg_rewrite_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(ruleOid));
rcscan = systable_beginscan(RewriteRelation, RewriteOidIndexId, true,
NULL, 1, skey);
tuple = systable_getnext(rcscan);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "could not find tuple for rule %u", ruleOid);
/*
* We had better grab AccessExclusiveLock to ensure that no queries are
* going on that might depend on this rule. (Note: a weaker lock would
* suffice if it's not an ON SELECT rule.)
*/
eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
event_relation = table_open(eventRelationOid, AccessExclusiveLock);
if (!allowSystemTableMods && IsSystemRelation(event_relation))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied: \"%s\" is a system catalog",
RelationGetRelationName(event_relation))));
/*
* Now delete the pg_rewrite tuple for the rule
*/
CatalogTupleDelete(RewriteRelation, &tuple->t_self);
systable_endscan(rcscan);
table_close(RewriteRelation, RowExclusiveLock);
/*
* Issue shared-inval notice to force all backends (including me!) to
* update relcache entries with the new rule set.
*/
CacheInvalidateRelcache(event_relation);
/* Close rel, but keep lock till commit... */
table_close(event_relation, NoLock);
}