CodeSOD: Query Query Query

This post was originally published on this site

The Daily WTF

Bob‘s employer had a data-driven application which wasn’t performing terribly well. They had some in-house database administrators, but their skills were more “keep things running,” and less “do deep optimizations”. The company opted to hire a contract DBA to come in, address the performance problems, and leave.

In actual fact, the DBA came in, ran some monitoring, and then simply wrote some guidance- generic, and frankly useless guidance. “Index on frequently queried fields,” and “ensure database statistics are gathered on the appropriate schedule.”

The only meaningful output of the contractor’s visit was a list of the badly performing stored procedures. Bob was given the list and told, “Go fix these.”

One stored procedure needed to populate variables with data from the order table. Specifically, it needed to collect sender_id, user_group, and file_ref from the orders table. Here’s how it did that:

if (@origin = -2 or @origin = -4 or

To read the full article click on the 'post' link at the top.