To VIEW or Not To VIEW ... That is the Question.

  • That was a well considered reply, G-Squared. The point you closed with (don't use this feature unless you know what you are doing) could be extended to virtually every T-SQL construct (i.e. Cursors, scalar functions, etc., etc., etc.).

    I suppose I get a little irritated when developers say, "What's wrong with that query? It works, doesn't it?" Well, yes, it does work. At least it returns data. (I presume it returns the correct data). However, I never hear about these queries until they stop working. When that happens the attitude seems to be that I, the Database Administrator, have done something to cause this failure or at least failed to do something to prevent it.

    Is anyone aware of an incident where a database administrator "went postal" on an application development department?

  • David Moutray (12/21/2011)


    That was a well considered reply, G-Squared. The point you closed with (don't use this feature unless you know what you are doing) could be extended to virtually every T-SQL construct (i.e. Cursors, scalar functions, etc., etc., etc.).

    I suppose I get a little irritated when developers say, "What's wrong with that query? It works, doesn't it?" Well, yes, it does work. At least it returns data. (I presume it returns the correct data). However, I never hear about these queries until they stop working. When that happens the attitude seems to be that I, the Database Administrator, have done something to cause this failure or at least failed to do something to prevent it.

    Is anyone aware of an incident where a database administrator "went postal" on an application development department?

    Thanks.

    Yeah, "do what you know" applies to every walk of life. I see far too many drivers every day who seem to think that "because the car can go 100 mph, that's how fast I'll drive". Same thing as cursors. Safe for a pro in controlled circumstances and environments, but not good for general use.

    Not aware of a full-on postal situation with a DBA and Kalishnakov, if that's what you mean (as per '80s incidents with actual body counts at post offices), and hope I never do. However, I have had to verbally spank some devs for doing eggregiously stupid things, if that counts. My most (in)famous was an incident involving a hierarchy crawl done by a recursive UDF with nested cursors in it. The dev, "but it worked just fine in our tests!" No mention that the test table had 6 rows of data in it, and the live table had tens of thousands of rows. There was a little shouting that day. Does that count?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • By the way, I'm in total agreement with that a, b, c stuff. Makes the code terrible to read sometimes. I try to use meaningful aliases line INV for the inventory table, SHIST for SalesHistory and so forth.

    I've found that views can be very useful if used correctly. Key word being 'correctly'. I've even had good luck with some aggregate views, which really have to be used correctly or you get a mess. I recall a system that had aggregates for film box office numbers maintained by triggers, which were very flaky and had errors in the data. Each time an exchange rate was modified for a week that was already reported, the trigger had to go back and re-populate the box office amounts. Just didn't work right. A proper aggregate view, with the actual box office numbers contained in an INCLUDE on the index we were using and calculating the other currency on the fly gave the correct results and didn't suffer much in performance.

    The main problem I've seen with views is trying to create a black box of business logic that just tries to do too much. In some cases it was for front end developers to make things easy for them. They just had to query a table. They didn't want to use stored procedures, which could easily do a divide and conquer type approach 'because a stored procedure isn't really an object like a table'. Pure silliness. I especially see this with Crystal Reports. Crystal has no problem with calling stored procedures.

    Some people just like a 'magic button' they can press to get the results they want and not have to think about it later. There is no magic. Only understanding the correct tools to use - which looks like magic.

    Todd Fifield

  • I have run across similar issues in my current position. Majority of performance problems are usually traced back to a view. This has led to a no views policy here as well. It wasn't so much that all the views were bad, they were just used very poorly. It was common for a developer to create a handful of generic views and then use them for everything. This caused a lot of problems as these generic views were usually nested with each other and often I would see select queries that would grab just one column from one table in a view of 10 or more tables, with subqueries and aggregates and a nested view with more of the same problems.

    Needless to say, it wasn't very hard to find the problems and point them out to the developers. It was quite the mess to untangle but we've seen a huge performance difference after cleaning it all up. Views still exist and the no views policy isn't as strict as it use to be. I like to use them for repeatable code. I recently found I was using the same CTE over and over again. So I just decided to throw it in a view and reference the view instead.

  • David Moutray (12/21/2011)


    Many developers seem to write code as if the compiler is charging by the character.

    Heh... think "cloud". πŸ˜›

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • David Moutray (12/21/2011)


    Is anyone aware of an incident where a database administrator "went postal" on an application development department?

    Yep... me. I got tired of some real crap code and did the only thing I could. I implemented standards, trained people, implemented 100% DBA code reviews, and got buy-in from management to be able to reject any and all code that didn't meet the standards for form, fit, function, performance, and resource usage as well as buy-in to do a full production lockdown so only DBAs could promote code.

    After that (it took several tons of high velocity pork chops over several months), rework and the associated research plummeted to near zero, productivity increased, code performance increased dramatically (large batch code dropping from 8 hours to something less than 10 minutes became the norm), we hit nearly zero-defects, and change controls dropped from an average of 6 hours for 6 stored procs to 15 minutes for 50. It was an all-out war on stupidity, ignorance (and they are not the same), rush jobs, and arrogant sots... and no one, not even management, was safe.

    I still get occasional accolades for what I and the other DBAs did there.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • In my organization, we have restricted the use of VIEW to avoid these problems. It’s equivalent to adding a TABLE (virtually) and requires approval from Architects / DBAs.

  • Jeff Moden (12/21/2011)


    David Moutray (12/21/2011)


    Is anyone aware of an incident where a database administrator "went postal" on an application development department?

    Yep... me. I got tired of some real crap code and did the only thing I could. I implemented standards, trained people, implemented 100% DBA code reviews, and got buy-in from management to be able to reject any and all code that didn't meet the standards for form, fit, function, performance, and resource usage as well as buy-in to do a full production lockdown so only DBAs could promote code.

    After that (it took several tons of high velocity pork chops over several months), rework and the associated research plummeted to near zero, productivity increased, code performance increased dramatically (large batch code dropping from 8 hours to something less than 10 minutes became the norm), we hit nearly zero-defects, and change controls dropped from an average of 6 hours for 6 stored procs to 15 minutes for 50. It was an all-out war on stupidity, ignorance (and they are not the same), rush jobs, and arrogant sots... and no one, not even management, was safe.

    I still get occasional accolades for what I and the other DBAs did there.

    That would make a pretty interesting book. (I'd buy it. Heck, I'd buy it for my whole team.) :smooooth:

    I probably shouldn't ask, but I can't help myself: what, pray tell, is a "high velocity pork chop?" :unsure:

  • David Moutray (12/21/2011)


    Jeff Moden (12/21/2011)


    David Moutray (12/21/2011)


    Is anyone aware of an incident where a database administrator "went postal" on an application development department?

    Yep... me. I got tired of some real crap code and did the only thing I could. I implemented standards, trained people, implemented 100% DBA code reviews, and got buy-in from management to be able to reject any and all code that didn't meet the standards for form, fit, function, performance, and resource usage as well as buy-in to do a full production lockdown so only DBAs could promote code.

    After that (it took several tons of high velocity pork chops over several months), rework and the associated research plummeted to near zero, productivity increased, code performance increased dramatically (large batch code dropping from 8 hours to something less than 10 minutes became the norm), we hit nearly zero-defects, and change controls dropped from an average of 6 hours for 6 stored procs to 15 minutes for 50. It was an all-out war on stupidity, ignorance (and they are not the same), rush jobs, and arrogant sots... and no one, not even management, was safe.

    I still get occasional accolades for what I and the other DBAs did there.

    That would make a pretty interesting book. (I'd buy it. Heck, I'd buy it for my whole team.) :smooooth:

    I probably shouldn't ask, but I can't help myself: what, pray tell, is a "high velocity pork chop?" :unsure:

    Caution: Its Jeff’s patented metaphor. πŸ˜‰

    (I have some idea but I am not very sure so I will let Jeff explain it and will watch the thread silently)

  • David Moutray (12/21/2011)


    I probably shouldn't ask, but I can't help myself: what, pray tell, is a "high velocity pork chop?" :unsure:

    Several years ago, some manager posted about a developer that ran rough-shod over everything. He wouldn't follow standards, wouldn't document his code, the list was nearly endless. The manager kept asking questions and everytime I made a suggestion as to how to handle the problem, the manager weinered out by saying "well, I can't do that... it might make him angry" and a whole bunch of other cruddy execuses for not being a good manager.

    After about 6 of these excuses, I finally got fed up and suggested that the manager first grow a working spine and then take the errant developer out for a nice dinner.... specifically a porkchop dinner... and that he should tie the developer to a chair and feed the porkchops to the developer one by one... with a Wrist Rocket at point blank range to get his attention.

    Some folks that witnessed the exchange of posts, picked up on the methaphor and, over time, the reference to "porkchops" and "high velocity pork" on SSC has come to mean "firmly and demonstrably explaining it to someone like it is along with the associated check on reality."

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (12/21/2011)


    David Moutray (12/21/2011)


    I probably shouldn't ask, but I can't help myself: what, pray tell, is a "high velocity pork chop?" :unsure:

    Several years ago, some manager posted about a developer that ran rough-shod over everything. He wouldn't follow standards, wouldn't document his code, the list was nearly endless. The manager kept asking questions and everytime I made a suggestion as to how to handle the problem, the manager weinered out by saying "well, I can't do that... it might make him angry" and a whole bunch of other cruddy execuses for not being a good manager.

    After about 6 of these excuses, I finally got fed up and suggested that the manager first grow a working spine and then take the errant developer out for a nice dinner.... specifically a porkchop dinner... and that he should tie the developer to a chair and feed the porkchops to the developer one by one... with a Wrist Rocket at point blank range to get his attention.

    Some folks that witnessed the exchange of posts, picked up on the methaphor and, over time, the reference to "porkchops" and "high velocity pork" on SSC has come to mean "firmly and demonstrably explaining it to someone like it is along with the associated check on reality."

    The place I worked in the '90s, it was refered to as a "severe reality adjustment". As in "Joe needs to get an SRA from his boss". I still like that phrase, but don't really get opportunities to use it much.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I like the phrase "High Velocity Pork Chop!" It is wonderfully obscure. πŸ™‚ Although, I think I prefer the imagery of a "high velocity meatball." Somehow, I think a meatball would fit into a wrist-rocket better than a pork chop. πŸ˜€

    For some reason, the term made me think of the cannons that they use to load test jet engines. A jet engine has to be able to suck down the occasional bird in flight without failing. (In fact, they rate jet engines on the number of birds they can suck down and still function.) So, during testing they use a cannon powered by compressed air to launch birds into a jet engine while it is running at different power levels. All very low-tech: they just get birds from the local grocery meat department. Usually they use turkeys, because a turkey is a pretty big bird. Ah yes, it is called a "Bird Cannon" or a "Bird Gun".

    Completely irrelevant, but I remember a story about an engineer who destroyed several million dollars worth of jet engines during testing, because he didn't know you were supposed to thaw the turkeys first! :w00t:

    Now that you mention it, that reminds me of some of the mind-bogglingly stupid things I've done with SQL Server! :sick:

  • David Moutray (12/22/2011)


    I like the phrase "High Velocity Pork Chop!" It is wonderfully obscure. πŸ™‚ Although, I think I prefer the imagery of a "high velocity meatball." Somehow, I think a meatball would fit into a wrist-rocket better than a pork chop. πŸ˜€

    For some reason, the term made me think of the cannons that they use to load test jet engines. A jet engine has to be able to suck down the occasional bird in flight without failing. (In fact, they rate jet engines on the number of birds they can suck down and still function.) So, during testing they use a cannon powered by compressed air to launch birds into a jet engine while it is running at different power levels. All very low-tech: they just get birds from the local grocery meat department. Usually they use turkeys, because a turkey is a pretty big bird. Ah yes, it is called a "Bird Cannon" or a "Bird Gun".

    Completely irrelevant, but I remember a story about an engineer who destroyed several million dollars worth of jet engines during testing, because he didn't know you were supposed to thaw the turkeys first! :w00t:

    Now that you mention it, that reminds me of some of the mind-bogglingly stupid things I've done with SQL Server! :sick:

    http://www.snopes.com/science/cannon.asp

    The frozen bird accident is an amusing story, but not really all that accurate.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Very funny article! Actually, I like the term "Rooster Booster" better than "Bird Cannon." :hehe:

    That reminds me of the Thanksgiving episode of "WKRP in Cincinnati" (an old 70's TV show). A radio station was doing a Turkey Give Away as a promotion during Thanksgiving. The station owner thought it would be really cool to drop live Turkeys from a helicopter onto a parking lot. He liked the idea of the birds fluttering down to earth, where the eager station fans could scoop them up and take them home.

    Well, when he actually tried it, the hapless birds dive-bombed the crowd like so many bricks - a scene of unspeakable carnage. At the end of the episode, the station owner says, "I swear to God - I thought Turkeys could fly." :w00t:

    40 years later, it still makes me laugh so hard that can't breathe!

  • David Moutray (12/22/2011)


    Very funny article! Actually, I like the term "Rooster Booster" better than "Bird Cannon." :hehe:

    That reminds me of the Thanksgiving episode of "WKRP in Cincinnati" (an old 70's TV show). A radio station was doing a Turkey Give Away as a promotion during Thanksgiving. The station owner thought it would be really cool to drop live Turkeys from a helicopter onto a parking lot. He liked the idea of the birds fluttering down to earth, where the eager station fans could scoop them up and take them home.

    Well, when he actually tried it, the hapless birds dive-bombed the crowd like so many bricks - a scene of unspeakable carnage. At the end of the episode, the station owner says, "I swear to God - I thought Turkeys could fly." :w00t:

    40 years later, it still makes me laugh so hard that can't breathe!

    I've seen that one! Hilarious!

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 15 posts - 16 through 30 (of 31 total)

You must be logged in to reply to this topic. Login to reply