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

Optimize SQL for Large Tables

HardSQL & Data Manipulation00:00
Practice interviewer
In session
5 left
00:00

Your question is Optimize SQL for Large Tables. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

You're a QA Engineer at Gen Digital (maker of Norton, Avast and LifeLock), sanity-checking a reporting query before it ships to the licensing dashboard team. The table license_activations holds roughly 10 million rows of subscription activation events, and this is the query a data engineer wants you to sign off on.

CREATE TABLE license_activations (
    activation_id BIGINT PRIMARY KEY,
    device_id BIGINT NOT NULL,
    product_sku VARCHAR(20) NOT NULL,
    activated_at TIMESTAMP NOT NULL,
    country_code CHAR(2) NOT NULL,
    status VARCHAR(20) NOT NULL
);
-- Indexes: idx_activated_at(activated_at), idx_device_id(device_id), idx_product_sku(product_sku)

SELECT DISTINCT
    la.device_id,
    la.product_sku,
    la.country_code,
    (SELECT COUNT(*) FROM license_activations la2
     WHERE la2.device_id = la.device_id) AS activation_count
FROM license_activations la
WHERE YEAR(la.activated_at) = 2024
  AND la.product_sku LIKE '%PRO'
  AND la.status = 'active'
ORDER BY activation_count DESC;

On a 10-million-row table this query times out in staging before it ever finishes. Explain, in plain language, why it is slow and what you would change to make it fast without changing what it returns.