X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8FD1DD899F for ; Fri, 2 Sep 2005 12:00:33 -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 15277-08 for ; Fri, 2 Sep 2005 15:00:29 +0000 (GMT) Received: from mail1.fluidhosting.com (mail1.fluidhosting.com [204.14.90.61]) by svr1.postgresql.org (Postfix) with SMTP id C1D4BD7769 for ; Fri, 2 Sep 2005 12:00:27 -0300 (ADT) Received: (qmail 3994 invoked by uid 399); 2 Sep 2005 15:00:27 -0000 Received: from 194-185-112-82.f5.ngi.it (HELO ?10.20.20.4?) (194.185.112.82) by mail1.fluidhosting.com with SMTP; 2 Sep 2005 15:00:27 -0000 Message-ID: <43186922.4060703@beccati.com> Date: Fri, 02 Sep 2005 17:00:50 +0200 From: Matteo Beccati User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Simon Riggs , pgsql-performance@postgresql.org Subject: Re: ORDER BY and LIMIT not propagated on inherited References: <43182789.4070307@beccati.com> <1125664532.3956.278.camel@localhost.localdomain> <43184B8F.2090505@beccati.com> <14074.1125672054@sss.pgh.pa.us> In-Reply-To: <14074.1125672054@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 required=5 tests=[AWL=0.007] X-Spam-Level: X-Archive-Number: 200509/55 X-Sequence-Number: 14363 Hi, >>The correct strategy IMHO would >>be applying the order by and limit for each child table (which results >>in an index scan, if possible), appending, then finally sorting a bunch >>of rows, and limiting again. > > This would be a win in some cases, and in many others a loss (ie, wasted > sort steps). The hard part is determining when to apply it. I don't actually know how many smaller separate sorts compare to a single big sort, but I guess the difference wouldn't be so big if the LIMIT is low. Add to this that you don't need to append the whole rowsets, but just smaller ones. Best regards -- Matteo Beccati http://phpadsnew.com http://phppgads.com