pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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 12:00:38 -0400
Message-ID: <29727.1090944038@sss.pgh.pa.us> (raw)
In-Reply-To: <29558.1090942807@sss.pgh.pa.us>
References: <6EE64EF3AB31D5448D0007DD34EEB34101AEFA@Herge.rcsinc.local>
	<29487.1090942399@sss.pgh.pa.us>
	<29558.1090942807@sss.pgh.pa.us>

I said:
> Oh, wait, you're right --- I'm mis-visualizing the situation.
> Hmm, it sure seems like there ought to be an easy way to do this...

The problem is that a multi-column index doesn't actually have the
semantics you want.  If you are willing to consider adding another
index (or replacing the existing 3-column guy), how about

create index ti on t((array[a,b,c]));

select * from t where array[a,b,c] >= array[a1,b1,c1]
order by array[a,b,c]
limit 1 offset 1;

This seems to do the right thing in 7.4 and later.  It does require that
all three columns have the same datatype though; you weren't specific
about the data model ...

			regards, tom lane



view thread (34+ messages)  latest in thread

Message-ID: <29727.1090944038@sss.pgh.pa.us>
Permalink:  ../29727.1090944038@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29727.1090944038@sss.pgh.pa.us

 · 

reply

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: <29727.1090944038@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