Level 1: Bronze
A memorized definition. Not wrong, but it stops there.
Add an index.
2 stars Asked often.
In one or two sentences
Find it through slow query records, see where the time goes in the execution plan, fix the index or the query shape, then measure again to confirm.
Say it out loud, or type it below. What you type never leaves this device.
A memorized definition. Not wrong, but it stops there.
Add an index.
Correct, but too broad or missing context.
Find the slow query and read its execution plan. If it scans the whole table, add an index or fix the condition.
Reaches principle, use and trade-off, with words that invite the next question.
Measure first. Pick queries by total time from a slow query log or statistics, then look in the plan for estimated rows that differ a lot from actual rows, full scans of big tables and large sorts. The fixes are an index, rewriting conditions, fetching fewer columns and rows, or changing the pagination method. If statistics are stale and the estimates are wrong, refresh them. After the change, measure again under the same conditions and check that you did not slow another query.
These are likely next questions from an interviewer. Think of your answer first, then press the button.
1 / 3
What is the N+1 problem?
Fetching one list and then sending one more query per item, so the query count grows. Reduce it with a join or by fetching in one batch.
2 / 3
Why is OFFSET pagination slow?
The database reads and discards the earlier rows, so deeper pages waste more. Fetching rows after the last key you saw is the alternative.
3 / 3
What if estimated and actual rows differ a lot?
Statistics may be stale, or columns may be correlated. Refresh statistics, and if it still differs, adjust the query or statistics settings.