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: constant vs function param differs in performance
Date: 2003-11-14 15:08:27
Message-ID: 01a601c3aac1$281e72c0$0403a8c0@fejleszt4
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Dear Gurus,

I have two SQL function that produce different times and I can't understand
why. Here is the basic difference between them:

CREATE FUNCTION test_const_1234 () RETURNS int4 AS '
SELECT ... 1234 ... 1234 .... 1234 ...
' LANGUAGE 'SQL';

CREATE FUNCTION test_param (int4) RETURNS int4 AS '
SELECT ... $1 .... $1 .... $1 ...
' LANGUAGE 'SQL';

Some sample times for different data:

test_const_1234() 450 msec
test_param(1234) 2700-4000 msec (probably disk cache)
test_const_5678() 13500 msec
test_param(5678) 14500 msec

Is there a sane explanation? a solution?
I can send more info if you wish.

TIA,
G.
------------------------------- cut here -------------------------------

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Nick Fankhauser 2003-11-14 16:00:38 Re: Seeking help with a query that takes too long
Previous Message Christopher Browne 2003-11-14 14:13:48 Re: Help with count(*)