vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Is there a version of this patch ready for application? --------------------------------------------------------------------------- Gurjeet Singh wrote: > On Tue, Mar 18, 2008 at 7:46 PM, Andrew Dunstan <andrew@dunslane.net> wrote: > > > > > > > > > > > > > Gurjeet Singh wrote: > > > On Fri, Mar 7, 2008 at 9:40 PM, Bruce Momjian <bruce@momjian.us > > > <mailto:bruce@momjian.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[.singh]@EnterpriseDB.com > singh.gurjeet@{ 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 -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + If your life is a hard drive, Christ can be your backup. + -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |
| |||
| Not that I know of. I never saw Gurjeet's completed code. cheers andrew Bruce Momjian wrote: > Is there a version of this patch ready for application? > > --------------------------------------------------------------------------- > > Gurjeet Singh wrote: > >> On Tue, Mar 18, 2008 at 7:46 PM, Andrew Dunstan <andrew@dunslane.net> wrote: >> >> >>> >>> >>> >>> Gurjeet Singh wrote: >>> >>>> On Fri, Mar 7, 2008 at 9:40 PM, Bruce Momjian <bruce@momjian.us >>>> <mailto:bruce@momjian.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[.singh]@EnterpriseDB.com >> singh.gurjeet@{ 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 >> > > -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |
| |||
| Andrew Dunstan wrote: > > Not that I know of. I never saw Gurjeet's completed code. This is Gurjeet's code, but it is not complete. http://archives.postgresql.org/pgsql...3/msg00668.php --------------------------------------------------------------------------- > > cheers > > andrew > > Bruce Momjian wrote: > > Is there a version of this patch ready for application? > > > > --------------------------------------------------------------------------- > > > > Gurjeet Singh wrote: > > > >> On Tue, Mar 18, 2008 at 7:46 PM, Andrew Dunstan <andrew@dunslane.net> wrote: > >> > >> > >>> > >>> > >>> > >>> Gurjeet Singh wrote: > >>> > >>>> On Fri, Mar 7, 2008 at 9:40 PM, Bruce Momjian <bruce@momjian.us > >>>> <mailto:bruce@momjian.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[.singh]@EnterpriseDB.com > >> singh.gurjeet@{ 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 > >> > > > > -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + If your life is a hard drive, Christ can be your backup. + -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |
| |||
| Right. In fact, I already had that part in fact - see http://people.planetpostgresql.org/a...e-Trigger.html What I was waiting for was the part where it gets put in the catalog, documented, etc. cheers andrew Bruce Momjian wrote: > Andrew Dunstan wrote: > >> Not that I know of. I never saw Gurjeet's completed code. >> > > This is Gurjeet's code, but it is not complete. > > http://archives.postgresql.org/pgsql...3/msg00668.php > > --------------------------------------------------------------------------- > > >> cheers >> >> andrew >> >> Bruce Momjian wrote: >> >>> Is there a version of this patch ready for application? >>> >>> --------------------------------------------------------------------------- >>> >>> Gurjeet Singh wrote: >>> >>> >>>> On Tue, Mar 18, 2008 at 7:46 PM, Andrew Dunstan <andrew@dunslane.net> wrote: >>>> >>>> >>>> >>>>> >>>>> Gurjeet Singh wrote: >>>>> >>>>> >>>>>> On Fri, Mar 7, 2008 at 9:40 PM, Bruce Momjian <bruce@momjian.us >>>>>> <mailto:bruce@momjian.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[.singh]@EnterpriseDB.com >>>> singh.gurjeet@{ 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 >>>> >>>> >>> >>> > > -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |
| |||
| Andrew Dunstan wrote: > > Right. In fact, I already had that part in fact - see > http://people.planetpostgresql.org/a...e-Trigger.html > > What I was waiting for was the part where it gets put in the catalog, > documented, etc. I can probably do that part. Send over what you have and I will work on it. Thanks. -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + If your life is a hard drive, Christ can be your backup. + -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |
| ||||
| Bruce Momjian wrote: > Andrew Dunstan wrote: > >> Right. In fact, I already had that part in fact - see >> http://people.planetpostgresql.org/a...e-Trigger.html >> >> What I was waiting for was the part where it gets put in the catalog, >> documented, etc. >> > > I can probably do that part. Send over what you have and I will work on > it. Thanks. > > It's very similar to what Gurjeet posted (but designed to work with earlier postgres versions) cheers andrew --- |#include "postgres.h" #include "commands/trigger.h" #include "access/htup.h" #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif /* for pre 8.3 */ #ifndef HeapTupleHeaderGetNatts #define HeapTupleHeaderGetNatts(th) ( (th)->t_natts ) #endif extern Datum min_update_trigger(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(min_update_trigger); Datum min_update_trigger(PG_FUNCTION_ARGS) { TriggerData *trigdata = (TriggerData *) fcinfo->context; HeapTuple newtuple, oldtuple, rettuple; /* make sure it's called as a trigger at all */ if (!CALLED_AS_TRIGGER(fcinfo)) elog(ERROR, "min_update_trigger: not called by trigger manager"); /* and that it's called on update */ if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) elog(ERROR, "min_update_trigger: not called on update"); /* and that it's called before update */ if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event)) elog(ERROR, "min_update_trigger: not called before update"); /* and that it's called for each row */ if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) elog(ERROR, "min_update_trigger: not called for each row"); /* get tuple dat, set default return */ rettuple = newtuple = trigdata->tg_newtuple; oldtuple = trigdata->tg_trigtuple; 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) rettuple = NULL; return PointerGetDatum(rettuple); }| -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers |