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 66A49D1CA66 for ; Wed, 28 Jul 2004 00:29:13 -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 04626-06 for ; Wed, 28 Jul 2004 03:29:09 +0000 (GMT) Received: from www.postgresql.com (www.postgresql.com [200.46.204.209]) by svr1.postgresql.org (Postfix) with ESMTP id C577BD1B7A9 for ; Wed, 28 Jul 2004 00:22:15 -0300 (ADT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by www.postgresql.com (Postfix) with ESMTP id 479ECCF726F for ; Tue, 27 Jul 2004 14:15:46 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1BpVVA-0004uG-00; Tue, 27 Jul 2004 13:12:32 -0400 To: "Merlin Moncure" Cc: Subject: Re: best way to fetch next/prev record based on index References: <6EE64EF3AB31D5448D0007DD34EEB34101AEF5@Herge.rcsinc.local> In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB34101AEF5@Herge.rcsinc.local> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 27 Jul 2004 13:12:31 -0400 Message-ID: <876589v0g0.fsf@stark.xeocode.com> Lines: 33 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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/194 X-Sequence-Number: 7585 > Interestingly, it is possible to rewrite the above query by switching > and with or and >= with >. However when written that way, the planner > almost never gets it right. Well, note it's still not really getting it right even in your case. It's doing an index scan on a>=a1 but if you have lots of values in your table where a=a1 and b (a1,b1,c1) to work however it doesn't. It appears to mean a>a1 AND b>b1 AND c>c1 which isn't at all what you want. I imagine the standard dictates this meaning. > My problem is deceptively simple: how you read the next record from a > table based on a given set of values? In practice, this is difficult to > implement. If anybody can suggest a alternative/better way to this, I'm > all ears. I've done this a million times for simple integer keys, but I've never had to do it for multi-column keys. It seems it would be nice if some syntax similar to (a,b,c) > (a1,b1,c1) worked for this. -- greg