Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimizing Slow JSON Processing

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Optimizing Slow JSON Processing. Start with the requirements and the two tables on the right.

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.

Problem

How do you optimize a script that is performing slowly on a large JSON dataset?

Write a PostgreSQL query that reports completed events from production batches in the requested date range. Extract only the required JSON attributes and exclude batches outside the range or from other source systems.

Output

  1. One row per batch date and event action.
  2. Columns: batch_date, action, event_count, and avg_duration_ms.
  3. Include completed events from production batches dated from 2026-01-01 through 2026-01-04, inclusive.
  4. Order by batch_date, then action.

Schema

event_batches
ColumnTypeDescription
batch_idPKINTUnique identifier for an ingestion batch
batch_dateDATEDate associated with the batch
source_systemVARCHAR(50)System that produced the batch
event_records
ColumnTypeDescription
record_idPKINTUnique identifier for an event record
batch_idINTBatch containing the event record
payloadVARCHAR(2000)JSON event payload stored as text
Tablesevent_batchesevent_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results