Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9A9791337B58 for ; Wed, 16 Feb 2011 03:24:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 61612-04 for ; Wed, 16 Feb 2011 07:24:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id AE0581337B4A for ; Wed, 16 Feb 2011 03:24:10 -0400 (AST) Received: (qmail invoked by alias); 16 Feb 2011 07:24:08 -0000 Received: from cpe.atm2-0-52453.esnxx3.customer.tele.dk (EHLO [10.10.10.22]) [80.164.162.42] by mail.gmx.net (mp010) with SMTP; 16 Feb 2011 08:24:08 +0100 X-Authenticated: #32880209 X-Provags-ID: V01U2FsdGVkX1+urMNyVyqu4Gq/4WNQqttOjnfIStF00Exhcvds2o fx2Agg5JHeUZdj Message-ID: <4D5B7B96.7010701@gmx.de> Date: Wed, 16 Feb 2011 08:24:06 +0100 From: "Kim A. Brandt" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: Marti Raudsepp CC: sthomas@peak6.com, "pgsql-performance@postgresql.org" Subject: Re: LIMIT on partitioned-table!? References: <4D5A8C6C.7080000@gmx.de> <4D5A9281.4010605@peak6.com> <4D5AD507.80800@gmx.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.905 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, PLING_QUERY=0.994, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201102/404 X-Sequence-Number: 42542 Thank you Marti, I will go with the ``reduced number of matched rows'' and naturally be waiting for postgres 9.1 expectantly. Kind regards, Kim On 2011-02-15 22:13, Marti Raudsepp wrote: > On Tue, Feb 15, 2011 at 21:33, Kim A. Brandt wrote: >> removing the ORDER BY worked. But I am afraid to ask this. How can I order >> by partition? It seams that the planner has picked a random(!?) order of >> partition to select from. The returned records, from the selected partition, >> are correctly sorted bythe index though. > > If a single query accesses more than one partition, PostgreSQL > currently cannot read the values in index-sorted order. Hence with > ORDER BY and LIMIT, PostgreSQL cannot return *any* results before it > has read all matching rows and then sorted them. Adding a LIMIT > doesn't help much. Your only bet is to reduce the number of matched > rows, or make sure that you only access a single partition. > > Increasing work_mem may speed up the sort step if you're hitting the > disk (EXPLAIN ANALYZE VERBOSE will tell you whether that's the case). > > This will change in PostgreSQL 9.1 which has a new Merge Append plan node. > > Regards, > Marti