Re: Mysterious performance of query because of plsql function in where condition

From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: "Peter Alberer" <h9351252(at)obelix(dot)wu-wien(dot)ac(dot)at>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Mysterious performance of query because of plsql function in where condition
Date: 2004-07-02 11:52:27
Message-ID: 4A8C38D1-CC1E-11D8-BD01-000D9366F0C4@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jefftrout(dot)com>
http://www.jefftrout.com/
http://www.stuarthamm.net/

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Bruno Wolff III 2004-07-02 13:07:10 Re: Mysterious performance of query because of plsql function in where condition
Previous Message PostgreSQL Bugs List 2004-07-02 07:50:07 BUG #1186: Broken Index?