From: | "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Why are stored procedures looked on so negatively? |
Date: | 2013-07-25 15:37:40 |
Message-ID: | 0AD01C53605506449BA127FB8B99E5E16832A765@FMSMSX114.amr.corp.intel.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I have a DB that relies heavily on recursive stored procedures that tap reflexive tables that store hierarchical data. These procedures are called from queries and return record streams. Temp tables are used to store collected data as the procedure runs up/down the hierarchy. And many other stored procedurea are called by the recursive procedure along the way to identify the correct hier path(s) to follow. These things run amazingly fast. Attempts others haev made to do this in perl-DBI were shaping up to be so slow that they were discarded early on, merely on that issue alone.
In another DB, I use stored procedures in triggers, again, recursive and working with hierarchy, only this time, inserting/updating/deleting records along the way. Again, fast as compared with the external "competition", but the matter of data integrity is another winner here because it makes it impossible for users at the SQL prompt to screw up the hierarchies with singular DML calls. The hierarchies end up being correct by construction. Ironically, a different group tried to implement this without triggers, sps or even PG (they used MySQL). And it's been nothing but headaches... poor performance and broken hierarchies all the time. When they asked me to port my PG triggers/sps to MySQL, I hit walls that involved... 1) inability to defer constraint checking (for foreign key constraints), 2) inability to leave cursors open in recursive calls (globally vs locally scoped cursors), and no support for "record" data types.
For me, the question is more along the lines of why I can't or shouldn't use stored procedures over external code, the default being sps.
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Pavel Stehule
Sent: Thursday, July 25, 2013 11:09 AM
To: Steve Atkins
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Why are stored procedures looked on so negatively?
2013/7/25 Steve Atkins <steve(at)blighty(dot)com>:
>
> On Jul 25, 2013, at 1:44 AM, Some Developer <someukdeveloper(at)gmail(dot)com> wrote:
>>>
>>
>> When I was talking about improving speed I was talking about reducing load on the app servers by putting more of the work load on the database server. I know that it won't actually save CPU cycles (one of the machines has to do it) but it will save load on the app servers. As I said above using the asynchronous abilities of libpq helps keep the app servers serving requests whilst the database gets on with its tasks.
>>
>
> App servers don't tend to maintain much global state, so are almost perfectly parallelizable. If you run out of CPU there, drop another cheap box in the rack.
>
> Database servers aren't. Once you top out a database server your main options are to replace it with a bigger box (increasingly expensive) or rearchitect the application (even more expensive).
>
> I'll always put more work on the cheaply scalable app servers if I can reduce the load on the database. Moving code to the database server for reasons of CPU cost (as opposed to, say, data or business rule consistency) seems an odd approach.
It is false idea.
What is a stored procedure? A few procedural construct and lot of SQL queries. A procedural code is +/- zero overhead - significantly more expensive are SQL queries - and these queries you will send from procedures and from application server too. I can say so good written stored procedures has zero negative effect on server performance - more it has positive effect due elimination network latency it decrease lock times.
Stored procedures is good environment for business logic implementation or workflow implementation and bad for expensive numeric calculations - and if you respect this rule, then stored procedures will be faster always with less server load.
Regards
Pavel
>
> Cheers,
> Steve
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To
> make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
From | Date | Subject | |
---|---|---|---|
Next Message | Giuseppe Broccolo | 2013-07-25 16:02:52 | Re: Rule Question |
Previous Message | bricklen | 2013-07-25 15:18:54 | Re: Rule Question |