From: | Jim Nasby <jnasby(at)pervasive(dot)com> |
---|---|
To: | Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> |
Cc: | "surabhi(dot)ahuja" <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: stored proc vs sql query string |
Date: | 2006-04-07 01:52:14 |
Message-ID: | DAFF57E8-0E51-49BC-8B98-345F5D9F2437@pervasive.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Apr 6, 2006, at 6:39 AM, Sean Davis wrote:
> On 4/6/06 12:12 AM, "surabhi.ahuja" <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)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(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2006-04-07 02:14:58 | Re: About checking all dead lock tables |
Previous Message | Michael Schmidt | 2006-04-07 01:03:48 | Re: programatic database dump |