Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id D94589FA37A for ; Fri, 10 Nov 2006 06:32:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 01904-03 for ; Fri, 10 Nov 2006 10:32:48 +0000 (UTC) X-Greylist: delayed 00:06:38.210848 by SQLgrey- Received: from cat.co.za (mailer.cat.co.za [196.33.33.51]) by postgresql.org (Postfix) with SMTP id 5D2489FA28E for ; Fri, 10 Nov 2006 06:32:37 -0400 (AST) Received: (qmail 21644 invoked by uid 1002); 10 Nov 2006 10:33:30 -0000 Received: from stuartb@cat.co.za by mail.cat.co.za by uid 807 with qmail-scanner-1.21 (clamscan: 0.70. Clear:RC:1(196.33.33.52):. Processed in 3.411318 secs); 10 Nov 2006 10:33:30 -0000 Received: from unknown (HELO STU95) (196.33.33.52) by 0 with SMTP; 10 Nov 2006 10:33:27 -0000 Message-ID: <021e01c704b1$ed75eec0$cc22a8c0@STU95> From: "Stuart Brooks" To: Subject: Constraint on multicolumn index Date: Fri, 10 Nov 2006 12:21:02 +0200 Organization: Intervid Technologies MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4927.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/107 X-Sequence-Number: 26759 Hi, I am not sure this can be done but I'm trying to constrain a sorted set efficiently using a multicolumn index in postgres. The (simplified) scenario is this: CREATE TABLE T ( a INT, b INT, c INT ); CREATE INDEX t_idx ON T(a,b,c); Now I can sort using t_idx: select * from T order by a,b,c; -- all good, seq scan using t_idx I can constrain on a single variable fine: select * from T where (a=10 AND b=100 AND c>1000) order by a,b,c; -- does seq scan on t_idx and uses the index in the constraint as expected But if I want the next item following t=(a=10,b=100,c=1000): select * from T where (a=10 AND b=100 AND c>1000) OR (a=10 AND b>100) OR (a>10) order by a,b,c; then it just does an ordinary filter, and basically does a sequence scan with no intelligence which isn't great if you've got a table of 20 million items. Is there any way short of issuing 3 queries and joining them that I can do this? I had hoped to be able to compare (a,b,c)>(10,100,1000) but of course that evaluates to (a>10) and (b>100) and (c>1000). It feels like there should be a simple solution to this... please help :) Thanks Stuart