Re: constant vs function param differs in performance

From: SZŰCS Gábor <surrano(at)mailbox(dot)hu>
To: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: constant vs function param differs in performance
Date: 2003-11-19 16:04:01
Message-ID: 01e301c3aeb6$bff63350$0403a8c0@fejleszt4
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Dear Tom,

Thanks for your early response.

An addition: the nastier difference increased by adding an index (it was an
essential index for this query):

func with param improved from 2700ms to 2300ms
func with constant improved from 400ms to 31ms
inline query improved from 390ms to 2ms

So am I reading correct and it is completely normal and can't be helped?
(couldn't have tried 7.4 yet)

In case it reveals something:

------------------------------- cut here -------------------------------
SELECT field FROM
(SELECT field, sum(something)=0 AS boolvalue
FROM
(SELECT * FROM subselect1 NATURAL LEFT JOIN subselect2
UNION
SELECT * FROM subselect3 NATURAL LEFT JOIN subselect4
) AS u
GROUP BY field) AS t
WHERE not boolvalue
ORDER BY simple_sql_func_returns_bool(field) DESC
LIMIT 1;
------------------------------- cut here -------------------------------

G.
----- Original Message -----
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Friday, November 14, 2003 9:59 PM

> "=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" <surrano(at)mailbox(dot)hu> writes:
> > I have two SQL function that produce different times and I can't
understand
> > why.
>
> The planner often produces different plans when there are constants in
> WHERE clauses than when there are variables, because it can get more
> accurate ideas of how many rows will be retrieved.
>
> regards, tom lane
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Manfred Koizar 2003-11-19 16:26:01 Re: TEXT column and indexing
Previous Message Josh Berkus 2003-11-19 16:00:11 Re: More detail on settings for pgavd?