This week, I want to sell you on two ideas. First, that you can make any query faster with:
- Zero hardware changes
- Zero index changes
- Zero structure
- Just a few simple character changes in every one of your queries
This change I will guarantee will make your queries screamingly faster. Never will your customer’s wait on query results again. You will have no blocking, no latch waits, no waiting whatsoever.
Before I tell you the technique
Firstly, remember this blog is in the Editorial category, not in any technical category. Secondly, notice what isn’t mentioned. Platform for one, will this change work on any platform? Yes, it will.
This in fact is the only tried and true way to make all of your queries run as fast as possible. Forget all the blogs telling you that these people know the exact patterns to follow for good SQL, I am going to reveal to you the actual answer for faster queries that will in fact, work 100% of the time.
That solution is
Add WHERE 1=2 to every query. Or WHERE False if you are working with an RDBMS that supports Boolean values.
This will make your queries very very fast. It will even be correct at least .001 % of the time.
Now you know exactly how to make your queries faster.
Bad advice right?
Oh yeah, really bad advice. But it is objectively true though. Returning 0 rows is always faster than returning more than 0 rows. And your query processing will more or less be “fetch metadata for output, and return no rows”:
Now obviously this is not real advice from me and is mostly just semi-humor and a way to make a point. But the introduction could have been a sales pitch for a real tool. The key here is to realize that much of the advice you are reading on the internet, be it from a blog, an LLM, or a post on LinkedIn…Don’t blindly listen to advice, even if it sounds compelling.
Most of the advice given is far more correct than my advice, but so much of the advice lacks nuance. Just the other day, I saw some of this sort of typical advice. Index all foreign keys. This is true of some foreign keys where there aren’t a lot of related values. For example invoice is related to invoice_line_item. But for a domain table with 10 row related to 100,000 an index is probably worthless… and I say probably because it is impossible to know the distribution of data that isn’t even real. But again, this isn’t a technical post.
Why do people put out such dreck? I have no idea. But while getting a lot of people telling you that you are wrong works for drumming up attention; is there really a point in doing that with technical posts? Is this a model that is going to get you anything of value?
Botton line
If you are an administrator of a system, you need to try to learn from people, but you also have to actually try out things too. There is a lot of great advice on the internet. And even more that is just plain good.
Most of the information on the internet isn’t perfect (I know I get it wrong plenty), but most well intentioned content has something you can learn from it. But if you can try out advice you read, try it. (And tell the author if you find out they are wrong!)
Not only will you be making your servers and data safer, but you will be learning something at the same time.



Leave a Reply