Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimizing Joins on Massive Tables
00:00
5 left

Optimizing Joins on Massive Tables

MediumSQL · PostgreSQL

Problem

Walk me through how you would optimize a join between two massive tables.

Use the provided Waymo-style segment and vehicle event tables. Return daily segment rows for January 2026, including segments without qualifying events. Exclude events with a NULL segment identifier from the event results.

Output

  1. One row per January segment, with segment_id, segment_date, region, speed_limit, event_count, and total_duration.
  2. Include zero-event segments and order by segment_date, then segment_id ascending.

Schema

route_segments
ColumnTypeDescription
segment_idPKINTUnique route segment identifier
segment_dateDATEDate associated with the route segment
regionVARCHAR(50)Operational region containing the segment
speed_limitNUMERIC(5,2)Posted speed limit for the segment
vehicle_events
ColumnTypeDescription
event_idPKINTUnique vehicle event identifier
segment_idINTRoute segment associated with the event
event_dateDATEDate on which the event occurred
event_typeVARCHAR(50)Vehicle software event category
duration_secondsNUMERIC(10,2)Event duration in seconds
Tablesroute_segmentsvehicle_events
Interviewer

Your question is Optimizing Joins on Massive Tables. 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.