From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <merlin.moncure@rcsonline.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: best way to fetch next/prev record based on index
Date: Tue, 27 Jul 2004 11:14:01 -0400
Message-ID: <28700.1090941241@sss.pgh.pa.us> (raw)
In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB34101AEF5@Herge.rcsinc.local>
References: <6EE64EF3AB31D5448D0007DD34EEB34101AEF5@Herge.rcsinc.local>
"Merlin Moncure" <merlin.moncure@rcsonline.com> writes:
> So, for a table t with a three part key over columns a,b,c, the query to
> read the next value from t for given values a1, b1, c1 is
> select * from t where
> a >= a1 and
> (a > a1 or b >= b1) and
> (a > a1 or b > b1 or c > c1)
> In about 95% of cases, the planner correctly selects the index t(a,b,c)
> and uses it.
I'm surprised it's that good. Why not do
select * from t where a >= a1 and b >= b1 and c >= c1
order by a,b,c
limit 1 offset 1;
which has a much more obvious translation to an indexscan.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, merlin.moncure@rcsonline.com
Subject: Re: best way to fetch next/prev record based on index
In-Reply-To: <28700.1090941241@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox