Skip site navigation (1) Skip section navigation (2)

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

From: Michael Adler <adler(at)pobox(dot)com>
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:13:24
Message-ID: 20040930141324.GA9170@pobox.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-performance
On Thu, Sep 30, 2004 at 09:45:51AM -0400, Merlin Moncure wrote:
> Now, if the same query is executed as a prepared statement,
> prepare ps(...) as select f(t.c) from t where [expr] limit 1;
> execute ps;
> 
> 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?  If necessary I should be able
> to set up a reproducible example.  The easy workaround is to not use
> prepared statements in these situations, but I need to be able to
> guarantee that f only executes once (even if that means exploring
> subqueries).


Here's another workaround that may let you use a prepared statement:

prepare ps(...) as 
select f(c) from (select c from t where [expr] limit 1) as t1

-Mike

In response to

pgsql-performance by date

Next:From: Merlin MoncureDate: 2004-09-30 14:19:12
Subject: Re: [HACKERS] spurious function execution in prepared statements.
Previous:From: Merlin MoncureDate: 2004-09-30 13:45:51
Subject: spurious function execution in prepared statements.

pgsql-hackers by date

Next:From: Merlin MoncureDate: 2004-09-30 14:19:12
Subject: Re: [HACKERS] spurious function execution in prepared statements.
Previous:From: Merlin MoncureDate: 2004-09-30 13:45:51
Subject: spurious function execution in prepared statements.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group