Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A22862E0057 for ; Tue, 19 Feb 2008 09:48:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 50406-07 for ; Tue, 19 Feb 2008 09:48:09 -0400 (AST) Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id 3C8892E0047 for ; Tue, 19 Feb 2008 09:48:17 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay05.plus.net with esmtp (Exim) id 1JRSpR-0002Op-M6; Tue, 19 Feb 2008 13:48:14 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 8CC4627405F; Tue, 19 Feb 2008 13:48:12 +0000 (GMT) Message-ID: <47BADE1C.10903@archonet.com> Date: Tue, 19 Feb 2008 13:48:12 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Stuart Brooks CC: pgsql-sql@postgresql.org Subject: Re: Am I wasting my time with partitions? References: <47BAB556.7060506@cat.co.za> In-Reply-To: <47BAB556.7060506@cat.co.za> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: a68cf4b4396eefa04252109d8dff1db7 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/150 X-Sequence-Number: 30241 Stuart Brooks wrote: > It seems to me that postgresql doesn't use indexes when being asked for > an ordered result sets from a partitioned table. I have an application > where this is critical, but I was hoping to use partitions because of > the ease of rotating out old rows. > metadb=> explain select * from l order by amount,lineitem_key limit 10; > QUERY PLAN > -> Seq Scan on l (cost=0.00..16.90 rows=690 width=88) > -> Seq Scan on l1 l (cost=0.00..4951.00 > rows=250000 width=49) > -> Seq Scan on l2 l (cost=0.00..5653.66 > rows=285466 width=49) > NB. Just addressing one of the inherited tables works fine. > > metadb=> explain select * from l1 order by amount,lineitem_key limit 10; Well, you don't have an index it can use to find the smallest (amount,lineitem) across all of lX. If PG was smart enough to figure out that it only needed to check l1, then you do. Unfortunately it isn't. If you add the constraint you use to partition by, does that help you? -- Richard Huxton Archonet Ltd