Re: Rewritten rows on unchanged values

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Adrian Klaver *EXTERN*" <adrian(dot)klaver(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Rewritten rows on unchanged values
Date: 2013-03-22 13:33:15
Message-ID: A737B7A37273E048B164557ADEF4A58B057CAB9A@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adrian Klaver wrote:
> On 03/22/2013 05:32 AM, Bertrand Janin wrote:
>> I noticed how rows were re-written to a different location (new ctid) even
>> without changes to the values. This illustrate what I mean:

>> -- ctid = (0,1)
>> SELECT id, xmin, ctid, value
>> FROM demo
>> WHERE id = 1;
>>
>> UPDATE demo
>> SET value = value
>> WHERE id = 1;
>>
>> -- ctid = (8,41)
>> SELECT id, xmin, ctid, value
>> FROM demo
>> WHERE id = 1;
>>
>> I'm curious as to what would prevent keeping the row where it is and maybe
>> change xmin in place?
>
> Because Postgres uses MVCC:
>
> http://www.postgresql.org/docs/9.2/static/mvcc-intro.html
>
> So an update is a delete and an insert and you are really seeing a new row.

You could use a BEFORE UPDATE trigger that returns
NULL if all fields are unchanged, but I'm not sure if
that is what the OP is looking for.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ryan Kelly 2013-03-22 13:41:10 Re: Rewritten rows on unchanged values
Previous Message Adrian Klaver 2013-03-22 13:16:11 Re: Rewritten rows on unchanged values