Re: Reasons to reorder results *within* a transaction?

From: Evan Jones <ej(at)evanjones(dot)ca>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Reasons to reorder results *within* a transaction?
Date: 2013-10-04 17:29:03
Message-ID: B3D403E6-A00F-459E-8A5C-F846884CE82C@evanjones.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Oct 4, 2013, at 13:03 , Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> That is not a valid assumption. For one thing, the default
> transaction isolation level is read committed, and at that
> isolation level you are not guaranteed to even get the same *rows*
> running the same query twice within the same transaction, much less
> in the same order.

I guess I should have mentioned that we are using serializable snapshot isolation (thanks for that, BTW!)

> if there is already a sequential
> scan in progress for another process, the new one will start at the
> point the other one is at, and "wrap around". This can save a lot
> of physical disk access, resulting in better performance.

OH! This totally, totally makes sense. This is *exactly* the kind of thing I was looking for, and I'll bet that is exactly what was happening in our case. The table is pretty small, so Postgres explain says it is doing a full table scan for this query. Thanks for the speedy insightful answer!

This is yet another example of something that when tracking down the bug, we knew immediately it was incorrect and probably wrong, but sometimes you don't notice these things the first time. The joys of software.

Evan

--
Work: https://www.mitro.co/ Personal: http://evanjones.ca/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2013-10-04 17:49:31 Re: Reasons to reorder results *within* a transaction?
Previous Message Kevin Grittner 2013-10-04 17:03:02 Re: Reasons to reorder results *within* a transaction?