Postgres optimizer, repeated function calls

From: "Sergey E(dot) Koposov" <math(at)sai(dot)msu(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Postgres optimizer, repeated function calls
Date: 2005-09-05 15:17:09
Message-ID: Pine.LNX.4.44.0509051853200.15334-100000@lnfm1.sai.msu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I have the following question about the Postgres optimizer.

I have two functions:

CREATE OR REPLACE FUNCTION test_func(float, OUT a bigint, OUT b bigint)
RETURNS record AS 'select test_func1($1)[1],test_func1($1)[2]
'LANGUAGE SQL IMMUTABLE;

and

CREATE OR REPLACE FUNCTION test_func1 (float)
RETURNS bigint[] AS '/home/math/skyindex/q3cube/operators/libxx.so',
'test_func1' LANGUAGE C IMMUTABLE;

And I was surprised to see that in such case, when I call the function
test_func, the function test_func1 is called twice. Why actually the
optimizer do so ? It should not be very difficult to optimize it to one call,
isn't it ?

With Best Regards,
Sergey

PS I tested this example with including in C code of test_func1 the static
counter of calls.

*****************************************************
Sergey E. Koposov
Max-Planck Institut fuer Astronomie
Web: http://lnfm1.sai.msu.ru/~math
E-mail: math(at)sai(dot)msu(dot)ru

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2005-09-05 15:43:16 Re: Call for 7.5 feature completion
Previous Message Christopher Kings-Lynne 2005-09-05 14:46:04 Re: Call for 7.5 feature completion