Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Troubleshooting Slow Queries
00:00
5 left

Troubleshooting Slow Queries

HardSQL · PostgreSQL

Problem

If a Clickhouse query is running slow, how would you troubleshoot the issue?

For this PostgreSQL exercise, translate the diagnostic step into a query over the supplied query log tables. Analyze executions from 2026-08-19 onward, retain executions lasting at least 1,000 milliseconds, and report repeated slow query patterns.

Output

  1. One row per query pattern and user
  2. Columns: user_name, query_pattern, execution_count, average_duration_ms, maximum_duration_ms, maximum_rows_scanned
  3. Include patterns with at least two qualifying executions
  4. Sort by average duration descending, then query pattern and user name ascending

Schema

query_logs
ColumnTypeDescription
query_log_idPKINTUnique query execution log identifier
user_idINTIdentifier of the user who ran the query
query_textTEXTSQL text recorded for the execution
duration_msINTExecution duration in milliseconds
rows_scannedINTNumber of rows scanned during execution
started_atTIMESTAMPExecution start timestamp
query_users
ColumnTypeDescription
user_idPKINTUnique query user identifier
user_nameVARCHAR(100)Display name of the query user
Tablesquery_logsquery_users
Interviewer

Your question is Troubleshooting Slow Queries. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.