Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Debug and Optimize Slow SQL

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Debug and Optimize Slow SQL. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

How would you debug and improve the efficiency of a slow SQL query?

Keep your answer focused on the steps you would take to identify the bottleneck and the changes you would make to improve runtime. Assume the query is used in PostgreSQL.

Output

  1. Provide a concise, ordered troubleshooting plan.
  2. Include the most important query rewrites and database changes you would consider.
  3. Mention how you would verify the improvement after each change.

Schema

customers
ColumnTypeDescription
customer_idPKBIGINTUnique customer identifier
customer_nameVARCHAR(255)Customer display name
is_activeBOOLEANWhether the customer is currently active
signup_dateDATEDate the customer account was created
orders
ColumnTypeDescription
order_idPKBIGINTUnique order identifier
customer_idBIGINTCustomer who placed the order
order_dateDATEDate the order was placed
total_amountNUMERIC(12,2)Order total amount
Tablesorderscustomers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results