X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 6700F9FA5DD for ; Sun, 11 Jun 2006 15:00:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 28969-01 for ; Sun, 11 Jun 2006 15:00:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stark.xeocode.com (stark.xeocode.com [216.58.44.227]) by postgresql.org (Postfix) with ESMTP id 898BA9FA3D7 for ; Sun, 11 Jun 2006 15:00:46 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1FpUEo-0001u5-00; Sun, 11 Jun 2006 14:00:38 -0400 To: "Craig A. James" Cc: pgsql-performance@postgresql.org Subject: Re: function not called if part of aggregate References: <448C505C.2080504@modgraph-usa.com> In-Reply-To: <448C505C.2080504@modgraph-usa.com> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 11 Jun 2006 14:00:38 -0400 Message-ID: <87ac8jfu7t.fsf@stark.xeocode.com> Lines: 17 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/121 X-Sequence-Number: 19478 "Craig A. James" writes: > This doesn't seem right to me -- how can the optimizer possibly know that a > function doesn't have a side effect, as in my case? Functions could do all > sorts of things, such as logging activity, filling in other tables, etc, etc. The optimizer can know this if the user tells it so by marking the function IMMUTABLE. If the function is marked VOLATILE then the optimizer can know it might have side effects. However that's not enough to explain what you've shown. How about you show the actual query and actual plan you're working with? The plan you've shown can't result from the query you sent. -- greg