ninja star T-SQL Tip - UNION vs. UNION ALL

by Michael Ceranski, posted on May 26 2009

The UNION and UNION ALL command look very similar but under the covers they do different things. The main difference between the two commands, is that UNION selects only distinct values, while UNION ALL selects all values (including duplicates).

Since the UNION statement eliminates all duplicate rows it does a SELECT DISTINCT on the result set. A SELECT DISTINCT is going to cause a table scan which can be a performance killer when you are dealing with large tables. If you know that all of the records returned from your queries are unique then use a UNION ALL instead. The UNION ALL should yield better results in terms of performance.

So now that you know the difference between the two statements you should be able to avoid future performance problems. Like G.I. Joe always said "KNOWING is half the battle".

Tags: ,

ninja star Things I Bet You Didn't Know About Using The WaitCursor

by Michael Ceranski, posted on May 21 2009

It is common for a developer to display a hour glass while their application is running a long operation. When running an application in Windows Vista the cursors typically look like this:

The Wait Cursor  The Default Cursor

In order to toggle the cursors, I typically will write a block of code that looks something like this:

   1:  this.Cursor = Cursors.WaitCursor;
   2:  try {
   3:    //Start long operation
   4:  }
   5:  finally { 
   6:     //use the finally block to guarantee that the cursor returns to normal
   7:     this.Cursor = Cursors.Default
   8:  }

To my surprise, this is not always the right technique. The problem with this approach is that it temporarily sets the WaitCursor, but does not guarantee that the WaitCursor will remain until the end of your operation. Why? Because other operations within your program can easily reset the cursor back to the Default cursor. Having the cursor flip back and forth is not only distracting but it also has the potential to make the user think that the operation has completed when in fact it is still running. So how do we avoid this? Well one way is the use the Form's UseWaitCursor property instead. Here is an example

   1:  this.UseWaitCursor = true;
   2:  try {
   3:    //Start long operation
   4:  }
   5:  finally { 
   6:     //use the finally block to guarantee that the cursor returns to normal
   7:     this.UseWaitCursor = false;
   8:  }

This method will display the WaitCursor for the specified form (referenced by the keyword this in the snippet above) or control and all its child controls until you set the UseWaitCursor back to false. If you have the situation where your operation blocks input not just to a single window but your entire application that you can use the Application.UseWaitCursor static property:

   1:  Application.UseWaitCursor = true;
   2:  try {
   3:    //Start long operation
   4:  }
   5:  finally { 
   6:     //use the finally block to guarantee that the cursor returns to normal
   7:     Application.UseWaitCursor = false;
   8:  }

By using the Application's UseWaitCursor property you will override any changes made to the cursor by a control of form. Therefore, guaranteeing that you have the right cursor displayed to the end user. Hopefully the next time you set the WaitCursor in your application you will remember these tips. After all, at the end of the day, user experience is the only thing that really matters.

Tags: ,

ninja star Windows 7 - Introducing Windows XP Mode

by Michael Ceranski, posted on May 19 2009

It seems like a lot of major corporations skipped the upgrade to Windows Vista. This was primarily due to the fact that a lot of their legacy apps did not play well with Vista. Microsoft has addressed this issue in Windows 7 by introducing XP Mode (XPM). XPM is a virtualization environment that will allow Windows 7 users to run legacy XP Apps with almost 100% compatibility. XPM is built on the next generation Virtual PC 7 product line, which requires processor-based virtualization on the underlying PC.

XP Mode requires a fully licensed copy of Windows XP SP3 which will be made available, for free, to users of Windows 7 Pro, Enterprise and Ultimate editions via a download from Microsoft's website. That's correct, you will not see a XP disk or license along with your Windows 7 Media, You will need to download them separately. XPM will not require you to run applications in a separate window or desktop like Virtual PC. Instead you will install applications inside the virtual XP environment. After installation you will end up with your standard start menu and desktop shortcuts to launch your applications.  When running the application the experience will be seamless and transparent, you will not even know that the application is being virtualized.

In conclusion, I think XPM will ease the pain for a lot of large corporations who want to upgrade but need to maintain compatibility with legacy applications. Of course, the only draw back is that you will have to make sure you have a processor equipped with hardware virtualization. This means big bucks for vendors like AMD and Intel. On a personal note, I will be upgrading my OS on the same day Windows 7 goes public. And this time I have some legitimate reasons to upgrade other than just wanting the latest eye candy.

Tags:

ninja star Source Code and Live Demo of Frogger Clone Now Available

by Michael Ceranski, posted on May 11 2009

I recently completed a series of articles on how to create a Frogger clone in Silverlight. Since the article was posted, I received quite a few emails from people requesting a copy of the source code. Therefore, I decided to post a modified version of the article along with source code on the codeproject.com.

Tags: ,

ninja star SQL Server Blamed for Windows 7 Download Crashes

by Michael Ceranski, posted on May 07 2009

When Windows 7 beta was made available to MSDN subscribers in January of this year, the resulting demand overwhelmed Microsoft's servers. The net result was that it delayed the launch by a day and it made Microsoft look foolish. 

After some diagnosis, the problem was found to be linked directly to excessive fragmentation levels in the SQL Server database. The number of requests to the MSDN and TechNet databases in less than an hour was more than a normal week's worth of traffic. The diagram below is from an internal Microsoft memo that shows processor usage over time. When the fragmentation began to worsen, CPU utilization spiked.

In order to fix the problem, indexes were defragged and the processor utilization dropped back to normal levels. Supposedly the Microsoft DBAs are now monitoring the status of the database every 30 minutes and rebuild the indexes every evening. Anyway, I just goes to show you that even Microsoft DBAs have bad days. Hopefully, the did not sit on the phone for a long time with premier support...LOL

About the author

MikeMichael Ceranski is a developer specializing in the .NET stack. I have spent time as a DBA, Web Developer and even a network engineer. Up til now most of my career has revolved around the .NET stack but I have recently taken an interest in microcontrollers which has forced me to get acquainted with lower level languages such as C, and C++.

View my resume

Sponsors