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
SQL Query Optimization
00:00
5 left

SQL Query Optimization

MediumSQL · PostgreSQL

Problem

How would you approach optimizing a slow-running SQL query in Distyl AI's production systems?

For this exercise, use the supplied execution, model, and workspace data to produce a baseline report of slow production workloads. Exclude executions without a duration, and explain how the query structure supports performance analysis.

Output

  1. One row per qualifying production workspace with workspace_name, completed_queries, average_duration_ms, and slowest_duration_ms.
  2. Ignore rows where duration_ms is NULL, and include only active models, completed executions from October 1, 2026 onward, and workspaces with an average duration above 1,000 milliseconds.
  3. Order by average duration descending, then workspace name ascending.

Schema

query_executions
ColumnTypeDescription
execution_idPKINTEGERUnique query execution identifier
model_idINTEGERReferenced model identifier
started_atTIMESTAMPExecution start timestamp
statusVARCHAR(20)Execution status
duration_msNUMERIC(12,2)Execution duration in milliseconds
rows_returnedINTEGERNumber of rows returned
models
ColumnTypeDescription
model_idPKINTEGERUnique model identifier
workspace_idINTEGERReferenced workspace identifier
model_nameVARCHAR(100)Model display name
is_activeBOOLEANWhether the model is active
workspaces
ColumnTypeDescription
workspace_idPKINTEGERUnique workspace identifier
workspace_nameVARCHAR(100)Workspace display name
environmentVARCHAR(20)Deployment environment
Tablesquery_executionsmodelsworkspaces
Interviewer

Your question is SQL Query Optimization. Start with the requirements and the three 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.