mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
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
85 lines
2.6 KiB
C
85 lines
2.6 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* trigfuncs.c
|
|
* Builtin functions for useful trigger support.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/backend/utils/adt/trigfuncs.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "access/htup_details.h"
|
|
#include "commands/trigger.h"
|
|
#include "utils/fmgrprotos.h"
|
|
|
|
|
|
/*
|
|
* suppress_redundant_updates_trigger
|
|
*
|
|
* This trigger function will inhibit an update from being done
|
|
* if the OLD and NEW records are identical.
|
|
*/
|
|
Datum
|
|
suppress_redundant_updates_trigger(PG_FUNCTION_ARGS)
|
|
{
|
|
TriggerData *trigdata = (TriggerData *) fcinfo->context;
|
|
HeapTuple newtuple,
|
|
oldtuple,
|
|
rettuple;
|
|
HeapTupleHeader newheader,
|
|
oldheader;
|
|
|
|
/* make sure it's called as a trigger */
|
|
if (!CALLED_AS_TRIGGER(fcinfo))
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
|
errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
|
|
|
|
/* and that it's called on update */
|
|
if (!TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
|
errmsg("suppress_redundant_updates_trigger: must be called on update")));
|
|
|
|
/* and that it's called before update */
|
|
if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
|
errmsg("suppress_redundant_updates_trigger: must be called before update")));
|
|
|
|
/* and that it's called for each row */
|
|
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
|
|
errmsg("suppress_redundant_updates_trigger: must be called for each row")));
|
|
|
|
/* get tuple data, set default result */
|
|
rettuple = newtuple = trigdata->tg_newtuple;
|
|
oldtuple = trigdata->tg_trigtuple;
|
|
|
|
newheader = newtuple->t_data;
|
|
oldheader = oldtuple->t_data;
|
|
|
|
/* if the tuple payload is the same ... */
|
|
if (newtuple->t_len == oldtuple->t_len &&
|
|
newheader->t_hoff == oldheader->t_hoff &&
|
|
(HeapTupleHeaderGetNatts(newheader) ==
|
|
HeapTupleHeaderGetNatts(oldheader)) &&
|
|
((newheader->t_infomask & ~HEAP_XACT_MASK) ==
|
|
(oldheader->t_infomask & ~HEAP_XACT_MASK)) &&
|
|
memcmp(((char *) newheader) + SizeofHeapTupleHeader,
|
|
((char *) oldheader) + SizeofHeapTupleHeader,
|
|
newtuple->t_len - SizeofHeapTupleHeader) == 0)
|
|
{
|
|
/* ... then suppress the update */
|
|
rettuple = NULL;
|
|
}
|
|
|
|
return PointerGetDatum(rettuple);
|
|
}
|