Re: [HACKERS] spurious function execution in prepared statements.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] spurious function execution in prepared statements.
Date: 2004-09-30 14:54:50
Message-ID: 16573.1096556090@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

"Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2004-09-30 14:58:34 Re: spurious function execution in prepared statements.
Previous Message Stephan Szabo 2004-09-30 14:45:40 Re: spurious function execution in prepared statements.

Browse pgsql-performance by date

  From Date Subject
Next Message Merlin Moncure 2004-09-30 14:58:34 Re: spurious function execution in prepared statements.
Previous Message Scott Dunn 2004-09-30 14:46:27 Web server to Database Taking forever