Interview questions
Predict the result, find the errors, explain the solution. You can read the questions without an account.
Level: SeniorReset all
46 questions
How many orders does
COUNT(o.id)count for a customer with no orders?Predict the resultJOIN and row countsHow do you find unmatched rows, and why can
NOT INcause problems?ExplainJOIN and row countsHow does the optimizer choose the
JOINorder, and why do outer joins restrict it?ExplainJOIN and row countsWhat does
CONCATreturn when one argument isNULL?Predict the resultNULLFind the bugs: counting anonymous events
Find the errorsNULLCan you sort
SELECT DISTINCTby a column outside the select list?Predict the resultQuery execution orderDoes the database execute queries in logical order?
ExplainQuery execution orderCan you select a column outside
GROUP BYwhen grouping by the primary key?Predict the resultGROUP BY / HAVINGWhich columns can you select in a query with
GROUP BY?ExplainGROUP BY / HAVINGHow do you avoid double-counting when aggregating after a
JOIN?ExplainGROUP BY / HAVINGCan you nest an aggregate inside a window function:
SUM(COUNT(*)) OVER ()?Predict the resultWindow functionsWhat does grouping by
id - ROW_NUMBER()find?Predict the resultWindow functionsWhat is a window frame, and how does
ROWSdiffer fromRANGE?ExplainWindow functionsHow do you calculate the median salary for each department using window functions?
ExplainWindow functionsHow many rows does
FETCH FIRST 2 ROWS WITH TIESreturn?Predict the resultDuplicates and top NFind the bugs: Second-highest salary in each department
Find the errorsDuplicates and top NHow do you paginate when the sort key can change?
ExplainDuplicates and top NHow many employees from
Saleswill this query find?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONHow does a CTE differ from a subquery, and is it materialized?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONWhen can you push a filter into a subquery?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONWill the table accept a second row with the same primary key?
Predict the resultIndexesHow does the primary key work in ClickHouse?
ExplainIndexesHow does a unique index handle
NULL?ExplainIndexesHow do data-skipping indexes work in ClickHouse?
ExplainIndexesHow do you diagnose index bloat?
ExplainIndexesWhat does
Recheck Condmean in a PostgreSQL execution plan?ExplainEXPLAIN and optimizationWhy doesn't PostgreSQL use a parallel execution plan?
ExplainEXPLAIN and optimizationHow can you tell whether a SQL query is CPU-bound or I/O-bound?
ExplainEXPLAIN and optimizationWhy does the same SQL query perform differently with different parameters?
ExplainEXPLAIN and optimizationCan you use
COUNT(*)withFOR UPDATE?Predict the resultTransactions and locksWhat is MVCC, and why does PostgreSQL need
VACUUM?ExplainTransactions and locksHow would you prevent overlapping reservations under concurrent requests in InnoDB?
ExplainTransactions and locksWhy does InnoDB use
gap locksandnext-key locks?ExplainTransactions and locksHow do you safely retry a transaction after an error?
ExplainTransactions and locksHow does
Sagadiffer from two-phase commit?ExplainTransactions and locksWill a foreign key allow an order for a nonexistent customer?
Predict the resultDDL, keys, and normalizationHow do you add a constraint to a large table under load?
ExplainDDL, keys, and normalizationHow would you choose between
BIGINT,UUID, and ID generation strategies?ExplainDDL, keys, and normalizationHow would you combine soft deletes with email uniqueness?
ExplainDDL, keys, and normalizationHow would you change a database schema without deploying all services at once?
ExplainDDL, keys, and normalization