Re: SRF called with optional NULL input runs 7x slower

From: Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: ML PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: SRF called with optional NULL input runs 7x slower
Date: 2007-09-24 05:44:28
Message-ID: 1190612668.17050.29.camel@neuromancer.home.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2007-09-24 at 00:18 -0400, Alvaro Herrera wrote:
> Ow Mun Heng wrote:
>
> > how can I debug or diagnose where the issues lies? Explain analyse
> > doesn't do much since this is a Function Scan anyway.
>
> Take them out of the function and EXPLAIN ANALYZE them as plain SQL.
> Note that you should take the parameters out of the literal, so you need
> to do something like
>
> PREPARE foo AS SELECT ... replace code with $1, etc ...
> EXPLAIN ANALYZE EXECUTE foo(code, ...)
>
> Otherwise they would be treated as constants so the queries would be
> planned differently.
>
> (untested, so correct the syntax appropriately)
>
Okay.. I tried that, but it seems like there's an issue w/ the CASE
statements.

When I tried the prepare w/

AND (CASE WHEN $3 IS NULL THEN true else d.code = any ($3) END)
AND (CASE WHEN $4 IS NULL THEN TRUE else D.id = any($4) END)

it ERRORs w/ could not determine data type of parameter $3

If I were to just use

AND D.code = ANY($3) then it would work.

Any other clues?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-09-24 06:31:48 Re: SRF called with optional NULL input runs 7x slower
Previous Message Ron Johnson 2007-09-24 05:28:38 Re: Is this good spec for a PostgreSQL server?