Slashdot Mirror


Stored Procedures - Good or Bad?

superid asks: "I'd like to get opinions and real world experiences that people have had with database centric applications that rely extensively on stored procedures. I believe that most enterprise class databases such as Oracle, MS-SQL, PostgreSQL, DB2 and others implement stored procedures. MySQL has been criticized for not supporting stored procedures and will be adding them in MySQL 5. The ANSI-92 SQL Standard also requires implementing some form of stored procedure (section 4.17). So, I'm asking Slashdot readers: if you were architecting a highly data-centric web based application today from a clean slate, how much (if at all) would/should stored procedures factor into your design? Where are they indispensable and where do they get in the way?" "The arguments for stored procedures are pretty straightforward: 1) Centralized code; 2) Compiled SQL is faster; 3) Enhanced security (as our application is over 15 years old, and consists of much legacy code, reimplementation and feature creep that now includes over 3000 stored procedures). At one time we had a client/server architecture so those three advantages were relevant. However, in the past 4 years we have moved everything to web front ends and I have argued that this is no longer true. Does it really matter if my business rules are centralized in stored procedures or in a set of php/asp scripts (ie, in the web tier)? Is it really important to shave compilation time when connection and execution times dominate? (and overall response is ok anyway?) Since the focal point is the webserver, shouldn't security be done there, rather than the DB?

In addition, you either have to have a dedicated T-SQL or PL/SQL coder who then is the weak link in your coding chain, or your pool of developers must become fluent in both your scripting language of choice as well as the SP language. I have experienced both of these approaches and found this to cause bottlenecks when 'the database guy' is unavailable and learning curve problems (bugs) with new coders getting familiar with the db language.

Finally, after staying with our DB engine choice for all these years we are acknowledging that they may not be around forever. Management has asked us to look into migrating our data and business logic to another DB choice. We'd sure love to just be able to point the web tier at a new data source but that is unattainable due to a convoluted tangle of db specific code."

11 of 629 comments (clear)

  1. SPs are good by TommyTyker · · Score: 2, Funny

    I actually miss them in my current job with mySQL. I used to like the way you could run a stored proc every X period to copy "live" data to "public" areas. Or, archive "public" data after "x" period of time. But then again, I am a micro$oft developer at heart, and all this Perl, CGI, Java, (even COBOL) on old RS6000 systems gives me a headache sometimes.

  2. Re:an important question.. by firebus · · Score: 2, Funny

    why are you posting if you don't have an answer?
    you are only giving me a headache.

  3. SPs are GOOOD by Anonymous Coward · · Score: 1, Funny

    Data controlled by the DBA good. Data controlled by developers or users... bad, very, very bad.

  4. My favorite SQL by Anonymous Coward · · Score: 1, Funny

    SELECT * FROM users WHERE CLUE = TRUE
    0 Rows Returned

    or if there are rows, fix it quick!

    DELETE
    FROM users
    WHERE CLUE=TRUE

  5. Depends by Billobob · · Score: 2, Funny

    If it can magically make 503 errors go away - yes if it does anything else - no

    --
    If you have to ask, you'll never know.
  6. Re:Two answers. by Anonymous Coward · · Score: 1, Funny
    If I were a bit more of a tinfoil hat wearing man, I'd be Slashdot makes some of these "Ask Slashdot" topics up because the ensuing flamewar will cause more page hits than usual.

    Call me weird, but I like these types of flamewars. I've done a little PHP hacking with MySQL and I'm curious about the issue of stored procedures, since I've never had the opportunity to use them.

  7. Meeting by cubicledrone · · Score: 4, Funny

    DBA: "I think we should use more stored procedures"

    Project Manager: "That would be consistent with our n-tiered strategy"

    Programmer: "But all of our business rules are in object libraries"

    Division Manager: "Could I get the ranch dressing? Thanks."

    DBA: "The right way is to put business logic in stored procedures. It's faster"

    Project Manager: "We're standardizing on faster programs across the enterprise"

    Programmer: "But we'll have to re-write the entire system!"

    Division Manager: "Pass the pepper. Thanks."

    DBA: "Oh, that's alright. We were going to upgrade the servers too. We can finish both jobs at the same time"

    Programmer: "We're upgrading the hardware too?! So basically we're building the entire company from nothing again, right?"

    Project Manager: "You're not being much of a team player"

    DBA: "The new system will be more robust and have new features"

    Division Manager: "Lets get the system built as soon as possible. We're laying off the entire division in a few weeks"

    Programmer: "WHAT?! I just signed a new car lease!!"

    Division Manager: "Pass the croutons please"

    --
    Business isn't willing to pay for products, innovation and careers, so we get brands, mortgage commercials and layoffs.
    1. Re:Meeting by mitchy · · Score: 5, Funny

      Project Manager: "So we need to start this project off as soon as possible, as this will become the foundation of several different applications."

      Programmer: "Wow, kewl, we should do it all in Perl."

      DBA: "We will definitely need to have a robust database if it is to power all these different apps."

      Programmer: "MySQL rules man! Besides, it is free."

      Division Manager: "Hmm, free is good. Can you manage the data in MySQL?"

      DBA: "Well, actually MySQL doesn't do..."

      Programmer: (interrupts DBA) "We don't need any of that relational integrity crap, that's just marketroid speak for Oracle, dude! All we need are a bunch of tables. I can wrap all of the SQL in a Perl package."

      DBA: "Then you will have dirty data, and we can only write apps in Perl if we have to use that library for access. This is really putting all of our eggs in one..."

      Project Manager: (interrupts DBA) "So this is free, right? I like free. My stepson talks about Perl, so it must be a totally hip language." (snorts)

      Division Manager: "So all of the database logic is now going to be written in Perl, right?"

      Programmer: "Absolutely! The database is only there to store data. We can check everything in the application. It will all work perfectly, because I am 3l337."

      DBA: "But that's like just using flatfiles, how are you going to..."

      Division Manager: (interrupts DBA) "Hey, if this is free, and you can do all the code, then we can cut half of our database specialists to save costs. That is a great idea."

      DBA: "You can do that, it is your company and all, but without triggers and some sort of stored procedures..."

      Programmer: "What's a stored procedure? Trigger? Isn't that a horse from the 60s?"

      Project Manager: "Heh, that's funny."

      DBA: "And if the next application needs to be done in Visual Basic, or some other language? Then you will have to write the whole thing over again because..."

      Programmer: "Look, this is easy, me and my buddies from the high school can pound this out over the weekend."

      Division Manager: "Now THAT's team spirit!"

      DBA: "But how can you ensure consistency of data? Your database cannot even enforce minimal compliance of..."

      Programmer: "Look, grumpy dude, I don't make mistakes. My code would never create dirty data, and besides, I'm 3l337."

      Project Manager: "Wow, my budget is going to look great after this."

      DBA: (leaves room, goes home and beats dog)

      --
      "The mind is a terrible thing to, um, uh, oh bollocks." -- Me
  8. Re:I don't use em unless I have to by 1001011010110101 · · Score: 2, Funny

    Pearl being my coding sister :) (Of course, I meant Perl)

  9. Re:Two answers. by johnstoj · · Score: 2, Funny

    As a DBA it should not be your job to write or maintain the code. There should be a separation of DBA and developer just like church and state should be separate.

  10. How to be a "real" DBA by 0x0d0a · · Score: 3, Funny

    What offended me was his strong implication that the two -- PHP/MySQL programming and real DB development -- are mutually exclusive. It's an attitude that I see a lot on Slashdot, and it pisses me off.

    Just:

    *) Ensure that your company blows inordinate amounts of money on software with expensive support to cover your ass. It doesn't matter whether it works better, but you should be able to point at someone else to blame if something goes wrong. This also means that you don't actually have to understand the product, and can trust your DBMS vendor's salesmen for all your information, which will chew it up into bite-size pieces and spoon-feed it to you.

    *) Act very self-important, talk down your nose to anyone that *doesn't* waste as much money as you, and treat your money-wasting as a mark of pride ("I have a $N million dollar budget this year!")

    *) Place "real" before every class of software you work with, and vaguely insinuate that there are technical (especially reliability) failings in any cheaper product than the one you use. It worked marvelously for "real UNIX admins" for years.

    *) Mention "Fortune X" frequently. For example "Fortune 500 DBAs with $5M budgets like me use *real* database software -- *we* can't afford downtime".

    *) Avoid, if at all possible, knowing anything about software or computers other than database interfaces and possibly a scripting language or two. It's also good to choose a single OS, learn only that, and then slip occasional comments about how other OSes are unreliable.

    *) Slowly begin slipping corporate acronyms into your speech. Use "ROI" whenever it's appropriate, and even when it isn't, to make it sound like other people are just slipshod and guessing numbers. "Enterprise class" is also good, since it implies, with only very vague factual requirements, that you work at a larger and more stodgy company that the person that you're trying to put down.

    You'll be well on your way to doing "real" database work in no time. :-)