Wednesday, November 26, 2025

Once again: I should lay off the SQL discussions on social media

LinkedIn is the worst for these SQL "hot takes." BTW regarding that phrase - "hot take" - I'm starting to find that annoying, even though I've used it myself before. It seems to be a way to attempt to say, "Hey I'm gonna be a bit of a jerk here and express an obnoxious opinion, but don't worry bro, I'm describing it as a 'hot take' so it's all good bro."




This one wouldn't bother me so much if they hadn't painted those who prefer the style that they dislike as "inexperienced." Look at the file names at the bottom of the post even: inexperienced.sql vs. experienced.sql. 🙄 It just feels condescending. And it's not an informed opinion either. It is feels based.

Below is my reply. I had to leave out some details and clarifications because I was fighting the LinkedIn character limit, but here goes:

Disagree, because I work with MySQL which processes WHERE bool less efficiently. It's not a universal problem-there's likely no discrepancy in most SQL engines, so fair enough if you prefer that style and it causes no issues for you. (SQL best practices should not be discussed universally IMO.)

In MySQL I see THIS take ~500 ms:

EXPLAIN ANALYZE
SELECT COUNT(*) FROM MY_TABLE WHERE IS_ACTIVE = TRUE;

-> Aggregate: count(0) (cost=456525 rows=1) (actual time=511..511 rows=1 loops=1)
-> Covering index lookup on MY_TABLE using IDX_IS_ACTIVE (IS_ACTIVE=true) <snip>


And THIS takes ~650 ms, because it results in a more complex search expression, and a more complex execution plan:

EXPLAIN ANALYZE
SELECT COUNT(*) FROM MY_TABLE WHERE IS_ACTIVE;

-> Aggregate: count(0) (cost=683424 rows=1) (actual time=657..657 rows=1 loops=1)
-> Filter: (0 <> MY_TABLE.IS_ACTIVE) <snip>
-> Covering index range scan on MY_TABLE using IDX_IS_ACTIVE over (NULL < IS_ACTIVE < 0) OR (0 < IS_ACTIVE) <snip>)


This behavior likely stems from MySQL's lack of a native boolean type - boolean is just an alias for tinyint - so in this example, IS_ACTIVE is a tinyint. Therefore if you do "WHERE <tinyint>" it says to check for any not null, non-zero value.


Guess I'm just inexperienced when I make MySQL queries run fairly significantly faster!

Ultimately, if you prefer one style and it works better for you and your SQL engine/DBMS, then great! But maybe others see something you don't - something measurable and tangible, not just feels based! So don't dismiss others as inexperienced before learning the other point of view. Not a good look.