🐘 Relational Databases in Depth — interview questions
11 questions. Filter by what the role asks for; open one for the six layers of the answer. The course is where the answers come from.
11 of 11
01Why does `WHERE status <> 'CLOSED'` silently drop rows where status is NULL, and why can COUNT(*) and COUNT(column) disagree on the same table?SQL fundamentalseasy0-2y02A LEFT JOIN in a query is supposed to keep customers with no orders, but the report is missing them. Separately, a total looks doubled. What are the two classic causes?Joinsmedium0-2y03How does a PreparedStatement's plan cache actually save work compared to concatenated SQL, and what's the trade-off — parameter sniffing — that comes with it?JDBCmedium3-5y04A service prepares the identical SQL text on every request — a fresh PreparedStatement object each time — executes it once, and closes it. Does this ever get pgjdbc's server-side plan-reuse benefit, and what would need to change?JDBC internalssenior8+y05Why does JDBC batching speed up a bulk insert, and what's the difference between plain addBatch()/executeBatch() and a driver's rewriteBatchedInserts setting?JDBCmedium3-5y06A team doubled maximum-pool-size to 50 after a connection-pool-exhaustion incident and it didn't help. Why not, and what does close() on a pooled connection actually do?Connection poolinghard5-8y07An index exists on (customer_id, status, placed_at), but a query filtering on customer_id and ordering by placed_at DESC LIMIT 20 is still slow. Why, and how would you fix the index?Indexesmedium3-5y08Why does a random UUID primary key hurt InnoDB in two distinct ways that it doesn't hurt PostgreSQL, and what does that say about choosing a primary key type?Indexessenior8+y09PostgreSQL defaults to read committed and MySQL defaults to repeatable read. What does a plain SELECT actually see differently under each engine's default, and where does a service moved between them tend to break?Transactionshard5-8y10A refund endpoint sums existing refunds, checks the total against the order amount, and inserts a new refund if there's room — all inside one @Transactional method. Two requests for the same order arrive at once and both succeed, over-refunding the order. Why didn't the transaction prevent it, and what actually fixes it?Transactionssenior8+y11Two workers each run SELECT ... FOR UPDATE SKIP LOCKED to claim the next pending job, and separately, a service on MySQL keeps hitting unexplained deadlocks under concurrent inserts into a range. Explain both mechanisms and how they relate.Lockingmedium5-8y