X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id 5893CCB9BC for ; Sun, 13 Jul 2003 10:14:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 53944-09 for ; Sun, 13 Jul 2003 10:14:50 +0000 (GMT) Received: from smtp.noos.fr (nan-smtp-11.noos.net [212.198.2.82]) by svr1.postgresql.org (Postfix) with ESMTP id 2C511CB9B0 for ; Sun, 13 Jul 2003 07:14:30 -0300 (ADT) Received: (qmail 107992672 invoked by uid 0); 13 Jul 2003 10:14:51 -0000 Received: from unknown (HELO gmendola) ([212.198.37.110]) (envelope-sender ) by 212.198.2.82 (qmail-ldap-1.03) with SMTP for ; 13 Jul 2003 10:14:51 -0000 Message-ID: <002f01c34937$ff7c48f0$10d4a8c0@mm.eutelsat.org> From: "Mendola Gaetano" To: "Tom Lane" Cc: , References: <002201c348ea$ab5f4300$10d4a8c0@mm.eutelsat.org> <19654.1058062747@sss.pgh.pa.us> Subject: Re: Function immutable is not during a reindex ? Date: Sun, 13 Jul 2003 14:12:15 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/122 X-Sequence-Number: 9462 On: Sunday, July 13, 2003 4:19 AM "Tom Lane" wrote: > "Mendola Gaetano" writes: > > the function is immutable but is executed 3 times > > ( one for each row). > > So? Sounds to me like it's working as intended. Well the documentation says: IMMUTABLE [...] If this option is given, any call of the function with all-constant arguments can be immediately replaced with the function value. The "index" behaviuor is different if the same function is used for a default value, or as field in a select: if I look at the table of the example: #\d t_a Table "public.t_a" Column | Type | Modifiers --------+---------+----------- a | integer | b | integer | Indexes: idxv btree (b) WHERE (test(3) = b) I was expecting: Indexes: idxv btree (b) WHERE (4 = b) look now the differrent behaviour: Used as field in a select: #select *, test(2) from t_a; NOTICE: test called a | b | test ---+---+------ 1 | 0 | 3 1 | 1 | 3 1 | 2 | 3 (3 rows) Used as default value: # alter table t_a alter b set default test(3); NOTICE: test called ALTER TABLE #\d t_a Table "public.t_a" Column | Type | Modifiers --------+---------+----------- a | integer | b | integer | default 4 Indexes: idxv btree (b) WHERE (test(3) = b) look that in the case of default value there is 4 and in case of index there is still the call. I don't like neather the result of the following experiment: # select *, test(a) from t_a; NOTICE: test called NOTICE: test called NOTICE: test called a | b | test ---+---+------ 1 | 0 | 2 1 | 1 | 2 1 | 2 | 2 (3 rows) here is called 3 times with the same argumen '1', I'm not sure but with the previous version of postgres 7.2.X or 7.1.X ( when there only way was write: WITH ( iscachable ) ) that select was like this: # select *, test(a) from t_a; NOTICE: test called a | b | test ---+---+------ 1 | 0 | 2 1 | 1 | 2 1 | 2 | 2 (3 rows) and test(1) was correctly cached, I'm not sure about this but you see the difference when is used inside a default value and inside an index ? Regards Gaetano Mendola