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
Optimizing Slow SQL Joins
00:00
5 left

Optimizing Slow SQL Joins

HardSQL · PostgreSQL

Problem

How would you optimize a query that is running slowly due to a massive join on high-frequency vehicle sensor logs for Waymo?

Write a PostgreSQL query that returns completed sessions in the specified time range, including sessions with no matching logs or alerts. Pre-aggregate the high-frequency data before joining it to session and vehicle records.

Output

  1. One row per qualifying session.
  2. Columns: vehicle_id, vehicle_model, session_id, started_at, valid_log_count, avg_speed_mps, peak_lidar_m, and open_alert_count.
  3. Include completed sessions from June 1 through June 2, 2026, ordered by started_at, then session_id.

Schema

vehicle_sensor_logs
ColumnTypeDescription
log_idPKINTUnique sensor log identifier
session_idINTDriving session identifier
recorded_atTIMESTAMPSensor reading timestamp
sensor_typeVARCHAR(30)Sensor measurement category
reading_valueDECIMAL(10,2)Numeric sensor reading
quality_validBOOLEANWhether the reading passed quality checks
sensor_alerts
ColumnTypeDescription
alert_idPKINTUnique alert identifier
session_idINTDriving session identifier
alert_timestampTIMESTAMPAlert creation timestamp
severityINTAlert severity from 1 through 3
is_openBOOLEANWhether the alert remains open
drive_sessions
ColumnTypeDescription
session_idPKINTUnique driving session identifier
vehicle_idINTVehicle assigned to the session
started_atTIMESTAMPSession start timestamp
is_completedBOOLEANWhether the session completed successfully
vehicles
ColumnTypeDescription
vehicle_idPKINTUnique Waymo vehicle identifier
vehicle_modelVARCHAR(50)Vehicle model name
Tablesvehicle_sensor_logssensor_alertsdrive_sessionsvehicles
Interviewer

Your question is Optimizing Slow SQL Joins. Start with the requirements and the four 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.