Re: SQL Function Performance - Mailing list pgsql-performance

From Mark Liberman
Subject Re: SQL Function Performance
Date
Msg-id 9D938282F8C6EE43B748B910386DE93E0138B3F1@srvgpimail1.GPI.local
Whole thread Raw
In response to SQL Function Performance  ("Adnan DURSUN" <a_dursun@hotmail.com>)
List pgsql-performance

I've run into this issue. It basically comes down to the plan that is being used inside the function is not the same as the plan used when you issue the query manually outside of the function.  Although I'm no expert on when plans are prepared and re-evaluated for functions, I know that they are not re-evaluated each time to execute the function.

So, what I did in such cases was to build up the sql query in a text variable inside my function, and then use the EXECUTE command inside the function.  When you use the EXECUTE command, the plan is prepared each time.  I know there is some minimal overhead of preparing the plan each time, but it seems like it's minor compared to the saving's you'll get.

- Mark

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] qsort again (was Re: Strange Create Index
Next
From: "Mark Liberman"
Date:
Subject: Re: SQL Function Performance