Re: stored proc vs sql query string

Поиск
Список
Период
Сортировка
От Jim Nasby
Тема Re: stored proc vs sql query string
Дата
Msg-id DAFF57E8-0E51-49BC-8B98-345F5D9F2437@pervasive.com
обсуждение исходный текст
Ответ на Re: stored proc vs sql query string  (Sean Davis <sdavis2@mail.nih.gov>)
Ответы Re: stored proc vs sql query string  ("Mark Aufflick" <mark-postgres@aufflick.com>)
Список pgsql-general
On Apr 6, 2006, at 6:39 AM, Sean Davis wrote:
> On 4/6/06 12:12 AM, "surabhi.ahuja" <surabhi.ahuja@iiitb.ac.in> wrote:
>
>> i have heard somewhere that writing a stored procedure, is much
>> better than
>> firing a sql query(such as select * from table_name) onto the
>> database.
>> is it true and if yes how?
>
> This isn't going to be true most of the time, I think.  Write SQL
> where you
> can, and where you can't (because you can't express something in
> SQL), write
> a procedure.  There are places where using a stored procedure can
> be more
> efficient, but I think starting with SQL, benchmarking and testing,
> and then
> determining what queries need special attention is the best way to
> go at the
> beginning.

You're forgetting that (at least in plpgsql), "raw" queries get
compiled into prepared statements. Prepared statements are faster to
execute than queries that have to be manually parsed every time. Of
course you can pass in prepared statements from the client side as
well, but if you stick with using stored procedures as an API to the
database you don't have to worry about forgetting to do that. And as
others have mentioned there's non-performance-related benefits to
using stored procs as well.
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461



В списке pgsql-general по дате отправления:

Предыдущее
От: Jim Nasby
Дата:
Сообщение: Re: autovacuum settings
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: Column descriptions - could they be propagated to new tables?