Re: best way to fetch next/prev record based on index - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: best way to fetch next/prev record based on index
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB34101AEFB@Herge.rcsinc.local
Whole thread Raw
In response to best way to fetch next/prev record based on index  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
List pgsql-performance
> Hmm, it sure seems like there ought to be an easy way to do this...

Here is the only alternative that I see:
create function column_stacker(text[] columns, text[] types) returns
text
[...]
language 'C' immutable;

the above function stacks the columns together in a single string for
easy range indexing.

create index on t_idx(array[t.a::text, t.b::text, t.c::text],
array['int', 'int', 'char(2)']);

This is a lot more complicated then it sounds but it can be done.  The
use of arrays is forced because of limitations in the way pg handles
parameters (no big deal).  The real disadvantage here is that it these
indexes don't help with normal queries so every key gets two indexes :(.

I'm just looking for a nudge in the right direction here...if the answer
is GIST, I'll start researching that, etc.  The ideal solution for me
would be a smarter planner or a simple C function to get the next record
out of the index (exposed through a UDF).

Everything has to stay generic...the ultimate goal is an ISAM driver for
pg.

Merlin



pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: best way to fetch next/prev record based on index
Next
From: Greg Stark
Date:
Subject: Re: best way to fetch next/prev record based on index