fun with stored procedures

I had some fun today optimizing a stored procedure. It was taking about 10 minutes to run, and I got it down to running in two seconds with a pretty minor change.

Without getting into too many gory details, it was basically doing a somewhat complicated PIVOT. It was using a SUM() call to generate a value that it was really just ignoring, just checking to see if it was null or not. I replaced the SUM() with a COUNT(), and checked for zero instead of null, and bam, 10 minutes down to 2 seconds.

This is the kind of stuff I really like doing — figuring out how to make a minor change in a bit of code that doesn’t affect the output, but results in a measurable improvement in performance. The only thing that’s still a little frustrating about this is that I don’t completely understand why the difference is so great. I have a general idea of why this worked, but something weird must be going on internally with the PIVOT option in MS SQL for this to have made such a huge difference.

less than helpful naming conventions

I had to do a little debugging work today in a system that I’m not too familiar with. I came across this line of code:

bool result = processor.Process();

If your code has reached the level of abstraction where the most meaningful name you can give a class is “Processor”, and the most meaningful name you can give the main routine in your class is “Process()”, then you may have gotten a little too abstract.

stored procedures

I had to debug a problem with a third-party e-commerce system today at work. It took a while to isolate the problem, and when I did, it led me to a certain stored procedure, which turned out to be 7400 lines long. I don’t think I’d ever seen a single stored proc quite that big before. Is that normal? I figured out what it was doing by running SQL Profiler, with the “TSQL_SPs” template that shows all the statements being executed within the procedure. With all the if/then logic in the proc, it was really only executing about 1000 lines of SQL for any given run. Still, that’s a lot to comb through just to figure out why the logic was returning wholesale prices instead of retail.

I also found a number of lengthy queries in the proc that ended with “and 1=2”, which would of course prevent that query from returning any results. I’m wondering why someone would do that rather than comment out the query. It made it fairly difficult to find the queries that were actually executing and returning results.

jQuery and CSS


I’ve been doing some client-side stuff at work recently, and I’m realizing that I don’t know nearly enough about some of this stuff. So, I picked up a book on jQuery, “jQuery: Novice to Ninja”, and another one on CSS, “CSS Mastery: Advanced Web Standards Solutions”. The jQuery book is pretty good, and a pretty easy read. I haven’t started the CSS book yet. I’m somewhat chagrined to admit that I’ve kind of been “faking it” with CSS for the last few years. I’ve never actually sat down and read a book on CSS or taken a class, or anything like that. I know enough to get by, usually, but I definitely need to learn more.

Meanwhile, I’ve put off my attempt to get through any more ASP.NET exams for now. I’m just letting work needs dictate my independent study time. At some point, hopefully, I’ll be up to speed on enough of the stuff at work that I can get back to the certification exams.

Oh, and as an example of how little I know about CSS, I really don’t know how to style a div so these two Amazon link boxes will line up horizontally instead of vertically. If I messed around with it for an hour, I’d probably figure it out. But I should probably know how to do something like that off the top of my head.

a fun project at work

I’m starting a project at work right now that’s going to involve integrating content from a WordPress blog and Picasa Web into an ASP.NET site. I’m a little leery about this, since it seems that this could all be done directly in .Net, and would be more efficient that way, but I’m game to give it a try. It should be fun. (Yeah, I know, now that I’ve said that, I’m doomed.)

ASP.NET and other .NET stuff

I spent some time today watching a couple of dnrTV episodes on Entity Framework. (Episodes 117 and 118.) I may be using Entity Framework in the near future.

Meanwhile, my progress through the book for 70-562 has stalled at chapter 6. I got through chapters 1-5 in about a week, but then last week, I got distracted from this due to a sudden burst of job interviews (three in a row). I also just wanted to take my time getting through the ASP.NET AJAX material, since I found it to be very interesting, and I wasn’t that familiar with it.

I bought a cheap used copy of Dino Esposito’s “Introducing Microsoft ASP.NET AJAX” book from Amazon, to supplement the overview in the 70-562 book. It looks like this will be a good place to start. I’m not sure now when I’ll be getting back to studying for 70-562, though, due to these side trips. I’d still like to take the test next month, but we’ll see if I have the time to do that or not.

What’s new in .NET Framework 4 Client Profile RTM

Here’s a good blog entry, explaining the .Net 4 client profile stuff. To some extent, I think this all just makes things even more complicated then they already were. On the other hand, there are certainly times when being able to distribute a smaller framework to the client is desirable.

Some post-VS2010 Launch Resources

This blog post pulls together some useful links to VS2010 post-launch resources.

I do now have a copy of VS2010, but I haven’t installed it yet. I want to concentrate on getting through the book on 70-562 for now. If I keep up my current pace (about one chapter per weekday), I should get through it by the end of the month. Then, I can take the test in early May. After that, I can figure out if I want to start messing with VS2010 or try to go a little further with VS2008 exams.

WPF Text in VS2010

WPF Text Blog : Blind Comparison VS2008 vs. VS2010
Speaking as a guy with relatively poor vision, I appreciate any efforts to make text more readable on computer screens. This blog entry is making the point that WPF now renders text as well as GDI, so the code editor in VS2010 should be as easy on the eyes as the one in VS2008. I downloaded VS2010 on Monday, but I haven’t actually installed it yet, so I can’t say how it looks on my own machine. Oh, and this blog entry also has links to a few interesting color schemes for Visual Studio. I need to try a couple of these.