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 DEB74533AF for ; Mon, 4 Apr 2005 16:14:28 +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 42154-10 for ; Mon, 4 Apr 2005 15:14:23 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2BA5352967 for ; Mon, 4 Apr 2005 16:14:22 +0100 (BST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id F15C730952; Mon, 4 Apr 2005 17:14:06 +0200 (MET DST) Date: Mon, 04 Apr 2005 17:18:24 +0200 From: Hannes Dorbath User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 X-Newsgroups: pgsql.performance Subject: Re: Query Optimizer Failure / Possible Bug References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Lines: 66 Message-ID: <42515478$0$5507$8fe63b2a@news.disputo.net> Organization: FirstUseNet Intermedia GmbH X-Complaints-To: abuse@disputo.de 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/207 X-Sequence-Number: 11604 Mhh. I have no clue about the internals of PostgreSQL and query planing, but to me as user this should really be a thing the optimizer has to work out.. On 03.04.2005 10:01, PFC wrote: > > Noticed this problem,too. > You can always make the calculation you want done once inside a set > returning function so it'll behave like a table, but that's ugly. > > On Mon, 28 Mar 2005 16:14:44 +0200, Hannes Dorbath > wrote: > >> hm, a few days and not a single reply :| >> >> any more information needed? test data? simplified test case? anything? >> >> >> thanks >> >> >> Hannes Dorbath wrote: >> >>> The query and the corresponding EXPLAIN is at >>> http://hannes.imos.net/query.txt >>> I'd like to use the column q.replaced_serials for multiple calculations >>> in the SELECT clause, but every time it is referenced there in some way >>> the whole query in the FROM clause returning q is executed again. >>> This doesn't make sense to me at all and eats performance. >>> If this wasn't clear enough, for every >>> q.replaced_serials AS some_column >>> in the SELECT clause there is new block of >>> --------------------------------------------------------------- >>> -> Aggregate (cost=884.23..884.23 rows=1 width=0) >>> -> Nested Loop (cost=0.00..884.23 rows=1 width=0) >>> -> Index Scan using ix_rma_ticket_serials_replace on >>> rma_ticket_serials rts (cost=0.00..122.35 >>> rows=190 width=4) >>> Index Cond: ("replace" = false) >>> -> Index Scan using pk_serials on serials s >>> (cost=0.00..3.51 rows=1 width=4) >>> Index Cond: (s.serial_id = "outer".serial_id) >>> Filter: ((article_no = $0) AND (delivery_id = $1)) >>> --------------------------------------------------------------- >>> in the EXPLAIN result. >>> For those who wonder why I do this FROM (SELECT...). I was >>> searching for >>> a way to use the result of an subselect for multiple calculations in the >>> SELECT clause and return that calculation results as individual columns. >>> I tested a bit further and found out that PG behaves the same in case q >>> is a view. This makes me wonder how efficient the optimizer can work >>> with views - or even worse - nested views. >>> Tested and reproduced on PG 7.4.1 linux and 8.0.0 win32. >>> Thanks in advance, >>> Hannes Dorbath >> >> > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >