Re: minimal update

From: "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Michael Glaesemann" <grzm(at)seespotcode(dot)net>, "David Fetter" <david(at)fetter(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: minimal update
Date: 2008-03-18 14:46:38
Message-ID: 65937bea0803180746s5ec87000gc755adfefece1441@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 18, 2008 at 7:46 PM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
>
>
>
>
> Gurjeet Singh wrote:
> > On Fri, Mar 7, 2008 at 9:40 PM, Bruce Momjian <bruce(at)momjian(dot)us
> > <mailto:bruce(at)momjian(dot)us>> wrote:
> >
> >
> > I assume don't want a TODO for this? (Suppress UPDATE no changed
> > columns)
> >
> >
> > I am starting to implement this. Do we want to have this trigger
> > function in the server, or in an external module?
> >
> >
>
> I have the trigger part of this done, in fact. What remains to be done
> is to add it to the catalog and document it. The intention is to make it
> a builtin as it will be generally useful. If you want to work on the
> remaining parts then I will happily ship you the C code for the trigger.
>
>
In fact, I just finished writing the C code and including it in the catalog
(Just tested that it's visible in the catalog). I will test it to see if it
does actually do what we want it to.

I have incorporated all the suggestions above. Would love to see your code
in the meantime.

Here's the C code:

Datum
trig_ignore_duplicate_updates( PG_FUNCTION_ARGS )
{
TriggerData *trigData;
HeapTuple oldTuple;
HeapTuple newTuple;

if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "trig_ignore_duplicate_updates: not called by trigger
manager.");

if( !TRIGGER_FIRED_BY_UPDATE(trigData->tg_event)
&& !TRIGGER_FIRED_BEFORE(trigData->tg_event)
&& !TRIGGER_FIRED_FOR_ROW(trigData->tg_event) )
{
elog(ERROR, "trig_ignore_duplicate_updates: Can only be executed for
UPDATE, BEFORE and FOR EACH ROW.");
}

trigData = (TriggerData *) fcinfo->context;
oldTuple = trigData->tg_trigtuple;
newTuple = trigData->tg_newtuple;

if (newTuple->t_len == oldTuple->t_len
&& newTuple->t_data->t_hoff == oldTuple->t_data->t_hoff
&& HeapTupleHeaderGetNatts(newTuple->t_data) ==
HeapTupleHeaderGetNatts(oldTuple->t_data)
&& (newTuple->t_data->t_infomask & ~HEAP_XACT_MASK)
== (oldTuple->t_data->t_infomask & ~HEAP_XACT_MASK)
&& memcmp( (char*)(newTuple->t_data) + offsetof(HeapTupleHeaderData,
t_bits),
(char*)(oldTuple->t_data) + offsetof(HeapTupleHeaderData,
t_bits),
newTuple->t_len - offsetof(HeapTupleHeaderData, t_bits)
) == 0 )
{
/* return without crating a new tuple */
return PointerGetDatum( NULL );
}

return PointerGetDatum( trigData->tg_newtuple );
}

--
gurjeet[(dot)singh](at)EnterpriseDB(dot)com
singh(dot)gurjeet(at){ gmail | hotmail | indiatimes | yahoo }.com

EnterpriseDB http://www.enterprisedb.com

17° 29' 34.37"N, 78° 30' 59.76"E - Hyderabad *
18° 32' 57.25"N, 73° 56' 25.42"E - Pune
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco

http://gurjeet.frihost.net

Mail sent from my BlackLaptop device

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2008-03-18 14:58:43 Re: [COMMITTERS] pgsql: Enable probes to work with Mac OS X Leopard and other OSes that
Previous Message Tom Lane 2008-03-18 14:39:03 Re: [COMMITTERS] pgsql: Enable probes to work with Mac OS X Leopard and other OSes that