Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.