Re: weirdness with the a sql update

From: Sven Willenberger <sven(at)dmv(dot)com>
To: tony_caduto(at)amsoftwaredesign(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: weirdness with the a sql update
Date: 2005-08-04 14:51:12
Message-ID: 1123167072.21749.4.camel@lanshark.dmv.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2005-08-04 at 09:19 -0500, Tony Caduto wrote:
> Hi,
>
> I just noticed this, if I do a update like this:
>
> update new_requests set name = 'tony' where request_id = 2
>
> If I do a select * from new_requests that record I just updated is now
> at the bottom , before the update it was at the top?
>
> Why is Postgresql changing the ordering of the results after a simple
> update?
> It almost looks like the record is being dropped and then readded to the
> end.
>
> Thanks,
>
If I understand MVCC correctly, a "new" tuple is actually created and
the "old" tuple is marked with an effective "end" transaction id (or
marked "dead" for any transactions with an id greater than the
transaction id that updated that particular tuple). Your subsequent
select then sees the "new" tuple and, in natural order, it would appear
at the bottom. Vacuuming is the process by which these "old" tuples are
examined and, if there are no transactions open with an id less than the
"end" transaction id associated with that dead tuple, it is removed (or
the space is marked as available for a new tuple to be written).

Sven

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-08-04 15:05:27 Re: weirdness with the a sql update
Previous Message Douglas McNaught 2005-08-04 14:41:36 Re: weirdness with the a sql update