Re: SQL Function Performance

From: "Mark Liberman" <mliberman(at)goldpocket(dot)com>
To: "Adnan DURSUN" <a_dursun(at)hotmail(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: SQL Function Performance
Date: 2006-02-13 20:06:27
Message-ID: 9D938282F8C6EE43B748B910386DE93E0138B3F1@srvgpimail1.GPI.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-performance by date

  From Date Subject
Next Message Adnan DURSUN 2006-02-13 20:23:52 Re: SQL Function Performance
Previous Message Adnan DURSUN 2006-02-13 19:44:40 Re: SQL Function Performance