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 346CED7839 for ; Fri, 2 Sep 2005 09:35:36 -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 68470-05 for ; Fri, 2 Sep 2005 12:35:34 +0000 (GMT) Received: from cmailm2.svr.pol.co.uk (cmailm2.svr.pol.co.uk [195.92.193.210]) by svr1.postgresql.org (Postfix) with ESMTP id 6E8A2D781C for ; Fri, 2 Sep 2005 09:35:33 -0300 (ADT) Received: from modem-2769.lemur.dialup.pol.co.uk ([217.135.138.209] helo=192.168.0.102) by cmailm2.svr.pol.co.uk with esmtp (Exim 4.41) id 1EBAlc-0001DK-E3; Fri, 02 Sep 2005 13:35:36 +0100 Subject: Re: ORDER BY and LIMIT not propagated on inherited From: Simon Riggs To: Matteo Beccati Cc: pgsql-performance@postgresql.org In-Reply-To: <43182789.4070307@beccati.com> References: <43182789.4070307@beccati.com> Content-Type: text/plain Organization: 2nd Quadrant Date: Fri, 02 Sep 2005 13:35:32 +0100 Message-Id: <1125664532.3956.278.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.052 required=5 tests=[AWL=0.002, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200509/51 X-Sequence-Number: 14359 On Fri, 2005-09-02 at 12:20 +0200, Matteo Beccati wrote: > I'm using inherited tables to partition some data which can grow very > large. Recently I discovered that a simple query that on a regular table > would use an index was instead using seq scans (70s vs a guessed 2s). > The well known query is: > > SELECT foo FROM bar ORDER BY foo DESC LIMIT 1 > > (The same applies for SELECT MIN(foo) FROM bar using 8.1) > > > The query plan generated when running the query on a table which has > inheritance forces the planner to choose a seq_scan for each table. > Wouldn't be a good thing to also promote ORDER BYs and LIMITs to each > subscan (like WHERE does)? The tuple_fraction implied by LIMIT is already passed through to each child table when using an inherited table structure. This would then be taken into account when plans are made for each child table. I don't think the situation you observe occurs as a result of query planning. Do your child tables have indexes on them? Indexes are not inherited onto child tables, so it is possible that there is no index for the planner to elect to use. Best Regards, Simon Riggs