Re: Mysterious performance of query because of plsql function in where condition - Mailing list pgsql-performance

From Jeff
Subject Re: Mysterious performance of query because of plsql function in where condition
Date
Msg-id 4A8C38D1-CC1E-11D8-BD01-000D9366F0C4@torgo.978.org
Whole thread Raw
In response to Mysterious performance of query because of plsql function in where condition  ("Peter Alberer" <h9351252@obelix.wu-wien.ac.at>)
List pgsql-performance
On Jul 2, 2004, at 3:48 AM, Peter Alberer wrote:
>
> Postgres seems to execute the function "submission_status" for every
> row
> of
> the submissions table (~1500 rows). The query therefore takes quite a
> lot
> time, although in fact no row is returned from the assignments table
> when
> the condition package_id=949589 is used.
>

Well, you need to think of it this way - PG has no idea what the
function does so it treats it as a "black box" - thus it has to run it
for each row to see what evaluates too - especially since it is in a
where clause.

If you really want a function there you can use a SQL function instead
of plpgsql - PG has smart enough to push that function up into your
query and let the optimizer look at the whole thing.

You can also take a look at the various flags you can use while
creating functions such as immutable, strict, etc. they can help

--
Jeff Trout <jeff@jefftrout.com>
http://www.jefftrout.com/
http://www.stuarthamm.net/


pgsql-performance by date:

Previous
From: "Peter Alberer"
Date:
Subject: Mysterious performance of query because of plsql function in where condition
Next
From: Bruno Wolff III
Date:
Subject: Re: Mysterious performance of query because of plsql function in where condition