I have had a few surprises since my last post. First, three people posted comments. That means three people are reading this blog, which is three more than I would have thought. I had no idea anyone was listening to my crazy ramblings. But there I was, sitting at my iMac the other night, and I saw an email arrive from someone I did not know. It took me a few seconds to understand what the email was about, and then I started to grasp the idea that I need to be very careful about what I put into my blog.
Second, I was careless in writing about the use of ‘select *’ forcing a full table scan. As was pointed out to me, that statement needs to be clarified. Funny, I do have my blogs proofread by a few people before posting them, and not one of them caught on to this issue, but I’ll talk more on that in a minute. To set the record straight, ‘select *’ itself does not force a table scan. There, I hope I made everyone a little happier.
The point I want to make is that often times the examples given during those training classes are too simple. I understand that instructors may not have enough time to teach everything correctly, but they could make a few statements about why ‘select *’ is not necessarily a good thing. Better yet, simply list the column names, include a WHERE clause, and mention something about indexes. Then they can mumble that consulting your local DBA would be in your best interest when it comes to performance tuning. Is that too much to ask? Too often I see what I call ‘lazy code’, where people take shortcuts without understanding the end result.
And do not get me started on those that insist on using a cursor for everything. I’ll reserve that for a later ramble.
Lastly, before you ever let me drive, see if someone more qualified is available first.
Now, how is it that the ‘select *’ statement got by everyone? Why is it that I used that to begin with? I did a quick check of some colleagues and asked them this question: “Does ‘select *’ force a full table scan”? Four out of five said “yes”, without even thinking about it. Why is that? I say it is because we have heard this same statement time and again and never dived into the details. After all, when it comes to query tuning you have Itzik and everyone else. Chances are whenever you hear something like that you will think for a few seconds, agree with it, and move on to something more important.
It’s like being told that “The Black Donnellys” is America’s Favorite New Drama. You do not readily have any information available, you could choose to believe the statement, but you move on with your life. But if you are told it enough times, you begin to believe it and then you start to watch it for yourself. Well, at least that’s what happened with me and CSI a few years back. Anyway, the point is that we probably all have statements like this, where we believe them to be true but never dived into the details for whatever reason.
I wonder what other statements we have heard enough times that we now simply believe them to be true, but in reality there is more to the story. Chances are they are not true, but the correct answer falls under our ever reliable “it depends”. How about “TRUNCATE statements are not logged”, or “MS Access is not a database”?
Any other statements out there that are not true, but most people simply accept as true?