in reply to Re^3: Moving SQL from perl to Stored Procedures
in thread Moving SQL from perl to Stored Procedures
Relational logic and database design is hard to master.That depends what you mean by "master". But a good working understanding of it is within the grasp of any good programmer.
Without for a moment doubting your grasp of relational theory and practice, I think that this is a pervasive--and generally wrong--assumption.
Here's another quote from Joel Spolsky. Funnily enough from the same article.
The SQL language is meant to abstract away the procedural steps that are needed to query a database, instead allowing you to define merely what you want and let the database figure out the procedural steps to query it. But in some cases, certain SQL queries are thousands of times slower than other logically equivalent queries. A famous example of this is that some SQL servers are dramatically faster if you specify "where a=b and b=c and a=c" than if you only specify "where a=b and b=c" even though the result set is the same. You're not supposed to have to care about the procedure, only the specification. But sometimes the abstraction leaks and causes horrible performance and you have to break out the query plan analyzer and study what it did wrong, and figure out how to make your query run faster.
A DBA, familiar with the type and version of the RDBMS he is using, can be expected to not only know this kind of detail, but also when it changes with releases/updates to the installation. And, when those changes occur, to scan those queries within his domain of responsibility looking for those likely to be affected by the change and schedule testing for possible improvements.
Even if the original application development team has moved on, and even the original DBA(s), those queries in existing applications that may be affected by upgrades are within his remit. Queries embedded within application code are not.
There are many similar areas where a DBA can be expected to have specialist knowledge beyond the scope of your average AP.
If there is an impedence mismatch between how the application works and how the database works, that mismatch is going to be a constant source of problems. As Joel Spolsky put it, abstractions leak. And the more that the abstraction tries to look different than the underlying reality, the more leakage there is.
The keyword there is If. Why would there be an impedance mismatch? Or rather, why is this any more likely with SPs?
Whatever API you wrap around your embedded SQL (eg. ... one possible option for how to build that application layer, namely use Class::DBI.), can equally be wrapped around calls to SPs. As you said later:
There has to be some sort of interface, and you ideally want that interface to be as cleanly defined on each side as possible.
The reasons for putting the business logic into SPs are:
I see no extra scope for being vulnerable to Joel's The Law of Leaky Abstractions, and having just re-read the article and the context in which you have quoted from it, I wonder if maybe you misunderstood him?
The way that you have put this presupposes that there are many independent applications accessing the same data, ...
I did say "DB design transcends applications for all but the most trivial.". Obviously, standalone applications are not affected this way, so using a trivial standalone application as counter argument is "straw man".
I don't know what you do, or who you do it for. However I happen to handle reporting needs for a high performance website. And I to know enough about databases to understand the difference between a transactional database and a data warehouse.If you attempt to run a large query against our transactional database,
Three points:
Either the argument stands up or it doesn't.
There's nothing wrong with placing transaction tables in a separate database and having them replicated back to the all encompassing offline DB. The point is that in order to allow the tables be replicated into the offline DB and permit ad-hoc investigative queries in conjunction with other application data there, the table designs need to be consistent with the wider schema.
Too often, datawarehousing only brings together a subset or summary representation of the live data, which precludes or inhibits benefits be derived from cross-application tie-ins.
Now you take a cheap shot about mixing Perl and HTML.
I didn't and don't see it as a cheap shot. I actually thought you would appreciate that reasoning as I know you to be an advocate of decoupled interfaces.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Moving SQL from perl to Stored Procedures
by tilly (Archbishop) on Sep 12, 2006 at 19:29 UTC |