Analytical Query Performance and Optimization Questions

Diagnosing and tuning analytical queries on distributed and warehouse engines. Covers reading and reasoning about query plans, join strategy and ordering including broadcast versus shuffle, statistics and cardinality estimation, materialized views and result caching, skew and spill diagnosis, workload management and concurrency, and the cost side of query performance on engines billed by bytes scanned or compute time. The altitude is the deep, engine-specific operational layer: what a real plan on a real warehouse engine is telling you and what to change. Generic single-engine query-tuning fundamentals, the physical layout of the data being scanned, and the choice of which managed platform to run on are covered separately.

MediumTechnical
56 practiced

A query filters a partitioned table with what looks like a clean date predicate, for example WHERE date = CAST(ts AS DATE), but it scans every partition instead of pruning. Explain why wrapping the partition column defeats pruning, and rewrite the predicate to restore it. Name at least two other common patterns that silently disable pruning, and explain why each one does.

MediumTechnical
51 practiced

You must decide whether a customer-lifetime-value report should be computed from raw transaction-level data or from pre-aggregated daily summaries. Explain the trade-offs in latency, accuracy, cost, and interactivity, and recommend which you would choose for an interactive BI dashboard versus a monthly finance report.

MediumTechnical
48 practiced

Explain how a warehouse-level query result cache (for example BigQuery's automatic result cache) works and how it interacts with underlying table updates. How would you design dashboard queries and BI-tool-level caching to get maximum benefit from the warehouse cache without silently serving stale results?

MediumTechnical
59 practiced

Given events(id, user_id, amount, event_time) and a materialized daily_user_totals(date, user_id, total_amount), write SQL (or precise pseudo-SQL) that incrementally updates daily_user_totals for only the dates present in a staging_events table, correctly handling inserts, updates, and deletes idempotently while minimizing locks on the target table.

HardSystem Design
56 practiced

Design a refresh strategy for materialized views that power an hourly dashboard joining a large fact table to several dimensions. Compare full, fast (log-based), and incremental (watermark/CDC) refresh: describe the operational complexity and consistency guarantee of each, provide the shape of the incremental refresh logic, and explain how you would prevent two concurrent refreshes from double-processing the same window, including a fallback to full refresh and how you would handle a source table backfill arriving up to 48 hours late.

Unlock Full Question Bank

Get access to all 24 Analytical Query Performance and Optimization interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.