Re: spurious function execution in prepared statements. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: spurious function execution in prepared statements.
Date
Msg-id 16573.1096556090@sss.pgh.pa.us
Whole thread Raw
In response to spurious function execution in prepared statements.  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
List pgsql-hackers
"Merlin Moncure" <merlin.moncure@rcsonline.com> writes:
> now, if ps ends up using a index scan on t, everything is ok.  However,
> if ps does a seqscan, f executes for every row on t examined until the
> [expr] criteria is met.  Is this a bug?

Works for me.

regression=# create function f(int) returns int as '
regression'# begin
regression'#   raise notice ''f(%)'', $1;
regression'#   return $1;
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select f(unique2) from tenk1 where unique2%2 = 1 limit 2;
NOTICE:  f(1)
NOTICE:  f(3)
 f
---
 1
 3
(2 rows)

regression=# prepare ps as
regression-# select f(unique2) from tenk1 where unique2%2 = 1 limit 2;
PREPARE
regression=# execute ps;
NOTICE:  f(1)
NOTICE:  f(3)
 f
---
 1
 3
(2 rows)

regression=#

You sure you aren't using f() in the WHERE clause?

            regards, tom lane

pgsql-hackers by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: [PERFORM] spurious function execution in prepared statements.
Next
From: "Merlin Moncure"
Date:
Subject: Re: [PERFORM] spurious function execution in prepared statements.