X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B044F5394B for ; Tue, 29 Mar 2005 01:15:07 +0100 (BST) 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 28853-10 for ; Tue, 29 Mar 2005 00:15:05 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id C43D553575 for ; Tue, 29 Mar 2005 01:15:04 +0100 (BST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id E9C4230952; Tue, 29 Mar 2005 02:15:03 +0200 (MET DST) From: Hannes Dorbath X-Newsgroups: pgsql.performance Subject: Re: Query Optimizer Failure / Possible Bug Date: Tue, 29 Mar 2005 02:15:01 +0200 Organization: Hub.Org Networking Services Lines: 42 Message-ID: References: <200503281151.17344.josh@agliodbs.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: <200503281151.17344.josh@agliodbs.com> To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200504/32 X-Sequence-Number: 11429 Thank you very much for your reply. I'll try to modify it. Josh Berkus wrote: > Hannes, > > >>The query and the corresponding EXPLAIN is at >> >>http://hannes.imos.net/query.txt > > > The problem is that you're using a complex corellated sub-select in the SELECT > clause: > > SELECT > d.delivery_id, > da.article_no, > da.amount, > ( > SELECT > COUNT(*) > FROM > serials s > INNER JOIN rma_ticket_serials rts ON ( > s.serial_id = rts.serial_id > ) > WHERE > s.article_no = da.article_no AND > s.delivery_id = d.delivery_id AND > rts.replace = FALSE > ) AS replaced_serials > > This means that the planner pretty much has to iterate over the subquery, > running it once for each row in the result set. If you want the optimizer > to use a JOIN structure instead, put the subselect in the FROM clause. > -- imos Gesellschaft fuer Internet-Marketing und Online-Services mbH Alfons-Feifel-Str. 9 // D-73037 Goeppingen // Stauferpark Ost Tel: 07161 93339-14 // Fax: 07161 93339-99 // Internet: www.imos.net