X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5A205D1D31F for ; Fri, 6 Feb 2004 08:50:55 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 96866-03 for ; Fri, 6 Feb 2004 04:50:55 -0400 (AST) Received: from anchor-post-37.mail.demon.net (anchor-post-36.mail.demon.net [194.217.242.86]) by svr1.postgresql.org (Postfix) with ESMTP id 36411D1D362 for ; Fri, 6 Feb 2004 04:50:53 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-37.mail.demon.net with esmtp (Exim 3.35 #1) id 1Ap1hN-0007LI-0b; Fri, 06 Feb 2004 08:50:53 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 2BB0416350; Fri, 6 Feb 2004 08:50:53 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 3EFDF15A6C; Fri, 6 Feb 2004 08:50:51 +0000 (GMT) From: Richard Huxton To: alvarezp@alvarezp.ods.org, pgsql-performance@postgresql.org Subject: Re: Seq scan on zero-parameters function Date: Fri, 6 Feb 2004 08:50:50 +0000 User-Agent: KMail/1.5 References: <4207.192.168.0.64.1076051944.squirrel@alvarezp.ods.org> In-Reply-To: <4207.192.168.0.64.1076051944.squirrel@alvarezp.ods.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402060850.50818.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/86 X-Sequence-Number: 5610 On Friday 06 February 2004 07:19, Octavio Alvarez wrote: > Hi! > > I'd like to know if this is expected behavior. These are two couples of > queries. In each couple, the first one has a WHERE field = function() > condition, just like the second one, but in the form WHERE field = > (SELECT function()). In my opinion, both should have the same execution > plan, as the function has no parameters and, therefore, is constant. Not necessarily constant - think about random() or timeofday(). Have you set the attributes on your function? http://www.postgresql.org/docs/7.4/static/sql-createfunction.html > pgdb=# explain analyze select count(*) from t_students where period = > (select current_period_id()); It's not entirely clear to me why this form is different from the other form though. -- Richard Huxton Archonet Ltd