X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4DD8FD1CA50 for ; Wed, 28 Jul 2004 00:28:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04936-03 for ; Wed, 28 Jul 2004 03:28:54 +0000 (GMT) Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) by svr1.postgresql.org (Postfix) with ESMTP id 93650D1CBDC for ; Wed, 28 Jul 2004 00:22:13 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by www.postgresql.com (Postfix) with ESMTP id 46721CF6D7A for ; Tue, 27 Jul 2004 13:01:54 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i6RG0cEG029728; Tue, 27 Jul 2004 12:00:39 -0400 (EDT) To: "Merlin Moncure" Cc: pgsql-performance@postgresql.org Subject: Re: best way to fetch next/prev record based on index 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> Comments: In-reply-to Tom Lane message dated "Tue, 27 Jul 2004 11:40:07 -0400" Date: Tue, 27 Jul 2004 12:00:38 -0400 Message-ID: <29727.1090944038@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/195 X-Sequence-Number: 7586 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