r/SQL • u/ElixirStylish • Apr 27 '26
Discussion What execution plan mistake do juniors make most often when they analyze queries?
A thing I see pretty often: junior devs open an execution plan, notice one big expensive-looking step, and lock onto that right away.
But the real issue is often somewhere else. Bad row estimates, missing index, messy join logic, parameter sniffing, key lookups, or just reading the plan without enough context.
What mistake do you see most often?
Could be stuff like chasing cost percentages, treating every scan like a disaster, or not comparing estimated vs actual rows. Also curious what helped you personally get better at reading plans, because most people learn this part the hard way.
36
u/wittgenstein1312 Apr 27 '26
I’ve never seen a junior analyze a query lol but I’m a backend developer where unfortunately ORMs and an aversion to SQL are rampant
11
u/Better-Credit6701 Apr 27 '26
Perhaps the most common thing is not knowing what to look for at all. Been analyzing a few this morning, most could be fixed with an index which we have a strange lacking of on our servers. I'll try an see what happens when I replace some CTEs with set based temp tables to see if that could help. Guess when you have 32 cores and 2 TB of ram, some things work better than they should because of a beefy server.
6
u/alinroc SQL Server DBA Apr 27 '26
Mistake #1 is jumping immediately to the execution plan without looking at the query itself for SARGability, unnecessary type conversions, cardinality, inefficient "methods" used that have been supplanted by functionality in newer versions of the RDBMS, total I/O performed, etc.
2
u/captainbastion Apr 27 '26
Query analysis is a highly complex topic which juniors usually aren't able to do. Heck, I work at a company with thousands of people and NOBODY does this or has time for it
1
u/dbomp Apr 28 '26
The biggest problem is trying to fix the query at all. It's a query that joins a lot of big tables without a where-clause; change the screen so that the user needs to specify at least one criterion that aligns with an index. It's a query that runs every minute for a dashboard that shows the percentage of purchase orders not invoiced in 10 days; it's not going to change meaningfully every minute; set it to run every hour.
Most of the time making the query faster doesn't address the underlying issue of "why is it doing this".
1
u/No_Resolution_9252 Apr 28 '26
viewing all scans as bad and trying to "fix" them
1
u/nep84 Apr 29 '26
missing the recursive nature of the statement. A statement that takes a second to run once is fast. A statement that takes a second to run 1000x is slow.
17
u/ComicOzzy sqlHippo Apr 27 '26
Where do you work that the juniors know anything about reading execution plans? I want to work there and mentor them.