Tuesday, June 21, 2011

ORDER BY - A Presentation Tier Function

I'm working on a project and providing some SQL optimizations for an n-Tier architecture application. Part of this optimization process is the removal of ORDER BY clauses and this got me into a discussion with the application developer about ORDER BY. His thought was that the database would be more efficient about sorting data so there are tons and tons of ordering clauses throughout the database views/queries and such.

It's not that SQL Server (or any database for that matter) is particularly efficient or inefficient at sorting but rather a question of where the task is most appropriate. More specifically I see sorting as a presentation tier activity, I'm not 100% against order by clauses and sorting results in the database but it is extra steps the database is taking to return data when those steps could be done in the presentation tier. In some cases SQL Server is doing it all, data, logic and presentation, but when you have a second application (web/thick client/etc) presenting the data to the client I think that is where the sorting should be done.

Today at the client the developer has SQL Server handling both the data and logic tiers of the architecture (with the three tiers being data, logic and presentation), this isn't a bad thing as it provides a unified interface to the system and allows for other applications to be created to interface with it. But, they also have SQL Server handling part of your presentation tier processing (the order by statements). If this is required (and with the current application design it is in the short term anyway).

One other interesting tidbit about this application's design is they have a ton of views that are all stacked on each other multiple levels deep (up to 8 in some cases). Even though we cannot remove all the order by statements from the database as it would affect the user interface, there's no need for the lower level views to be doing sorting when the levels above them are also sorting the same data. If the query isn't being called directly by the application, remove the order by clauses and let the sort process be done once at the top level with the final result.

This will also reduce the IO load on tempdb, and help resolve another issue this client is experiencing.

This guy uses an interesting analogy to describe how the sql server plans are built. If you go to the bottom of the article he talks about his thoughts on order by:


Why I Hate “ORDER BY”

We believe in division of labor in the Ozar house. When I get home from shopping, I deliver the bags into the dining room table. From there, it’s Erika’s job to put things away in the various cupboards and closets. I know that I could make Erika’s job easier if I sorted items as I loaded them into the car, but that just doesn’t make sense. It’s not efficient for me to stop what I’m doing in the middle of the shopping trip, move things around between bags, and get them in exactly the right order for efficient cabinet loading. There’s plenty of space for efficient sorting when I get home.
Likewise, I don’t want my SQL Server sorting data. The more processing that I can offload to web servers, application servers, and thick clients, the better. SQL Server Enterprise Edition is $30k/CPU, but your web/app servers are likely a great deal cheaper, and you’ve probably got much better methods of scaling out your app server tier. We just don’t have a good way of scaling out SQL Server queries until Denali AlwaysOn hits.

Thursday, March 18, 2010

PALM is dieing

Ok, a while back (about a month ago) I bought 10 Aug put contracts for PALM @$6. Today I bought 5 more August puts @$5 so I'm financially biased for palm to do not so well.

After hours trading looks like I made a good choice.

That said I expect one of 2 outcomes for PALM as a company:

  1. They file for bankruptcy
  2. They are purchased
Some analysts say that their patents & webOS still provide enough value for a possible purchase by dell/hp (even some have mentioned Microsoft or Research in Motion). I don't really see value there that would justify such a purchase.

The one thing I might possibly see would be Google buying them. Both webOS and Android are based in linux. Both use some of the same hardware (chip level). Google's purchase would be to merge the best of both world features.

That said, I still think it's a long shot. Rather than buying the company and getting all the associated liabilities, Google (or hp or dell or whoever) could just make job offers to palm's developers (Google looking to merge features into Android, the others looking to build a viable mobile platform)....

Because webOS is linux based I dont see either RIMM or MSFT buying PALM.

I fully expect Palm to end it's life in bankruptcy.

Saturday, February 02, 2008

Harmony 890 Universal Remote

I love this remote, it rocks! One annoying thing is that you'll be using it with the default settings for various activities and expect some button to behave a specific way when it doesn't. It's quite easy to re-program though. I'd highly recommend it (or the non-RF version 880) if you decide you want a universal remote. Actually if you don't need the RF feature checkout their new Harmony One that's been re-designed. Although these buttons are OK, they're a bit small and can be annoying in their shape/layout, the harmony one appears to have been redesigned to correct these issues.

Now if Logitech would just release a new version of the Harmony One that has built in RF and Bluetooth (to controll the PS3) I'd be willing to upgrade.

Thursday, December 27, 2007

Chocolate Mint Marvels

This recipe came out of the American Way magazine. After we made them the first time they quickly became my favorite cookies ever, the only problem is (and that's if you could consider this a problem) they are so rich I can only eat one or two per sitting. I will say that I am normally only able to use 1 package of Andes mints for the cookies, but the mints are so good it's nice to have extras lying around.


Chocolate Mint Marvels

submitted by Chris Wessling, senior editor
— from his mother Mary Ann Wessling’s recipe

¾ cup butter1
½ cups brown sugar
2 cups chocolate chips
2 eggs
2½ cups flour
1¼ teaspoons baking soda
3 or 4 packages of Andes mints

Preheat oven to 350°. Melt butter and brown sugar in saucepan over low heat. Add chocolate chips and stir to melt; put mixture into a bowl and let cool. Add eggs, and then mix in flour and baking soda. Chill dough for 1 hour. Roll into balls and place on baking sheet. Bake for 9 minutes. Remove cookies from oven and place an Andes mint on each one. As the candy melts, spread it across the top of the cookie with a butter knife. Makes 3 dozen.

Thursday, November 29, 2007

Pig Sweaters


While I don't really think anyone is making sweaters from the coarse hair on these pigs it is rather interesting. I read this article in the Spokane Review about a guy who loved the pork so much he imported some pigs from Europe. His site lists the first set of pigs as being available in the summer of 2008 at a price of $540 for 35lbs! I'm interested in trying some, but holy smokes, that's a lot of money to try some pork. Maybe once he gets going with his pigs Mr. Putman will sell it in 1lb increments so I can buy a pound of this super good Mangalitsa pork and try it out.
The significant problems we have cannot be solved at the same level of thinking with which we created them.
    -- Albert Einstein (1879 - 1955)