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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Optimize Massive Distributed Joins
00:00
5 left

Optimize Massive Distributed Joins

HardSQL · PostgreSQL

Problem

How do you optimize query performance in a distributed data warehouse when dealing with massive join operations?

Use the supplied PostgreSQL tables to write a query that returns metrics for every active entity. Include only current aliases, events from 2025-01-01 onward, and confirmed matches with a score of at least 0.80 linked to a current alias. The result should avoid multiplying rows across independent one-to-many relationships.

Output

  1. One row per active entity, including entities with no qualifying events or matches.
  2. Columns: entity_id, entity_name, current_alias_count, recent_event_count, confirmed_match_count, max_match_score.
  3. Order by max_match_score descending with nulls last, then entity_id ascending.

Schema

entities
ColumnTypeDescription
entity_idPKINTUnique entity identifier
entity_nameVARCHAR(100)Entity display name
regionVARCHAR(50)Entity operating region
is_activeBOOLEANWhether the entity is active
entity_aliases
ColumnTypeDescription
alias_idPKINTUnique alias identifier
entity_idINTReferenced entity
alias_textVARCHAR(150)Known alternate entity name
alias_typeVARCHAR(40)Alias classification
is_currentBOOLEANWhether the alias is currently valid
relationship_events
ColumnTypeDescription
event_idPKINTUnique event identifier
entity_idINTReferenced entity
event_dateDATEDate of the relationship event
event_typeVARCHAR(40)Event category
severityINTOptional event severity
entity_matches
ColumnTypeDescription
match_idPKINTUnique match identifier
entity_idINTMatched entity
alias_idINTAlias involved in the match
match_scoreNUMERIC(4,3)Match confidence score
statusVARCHAR(30)Match review status
matched_onDATEDate the match was created
Tablesentitiesentity_aliasesrelationship_eventsentity_matches
Interviewer

Your question is Optimize Massive Distributed 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.