InterviewStack.io LogoInterviewStack.io

Set Operations and Complex Aggregations Questions

Understanding UNION, UNION ALL, EXCEPT, INTERSECT operations and their performance implications. Complex GROUP BY queries, HAVING clauses, and multi-level aggregations.

MediumTechnical
81 practiced
Scenario troubleshooting: A nightly pipeline that aggregates event counts per user T fails with OOM at the GROUP BY step on the compute cluster. The input volume has not changed. Describe a systematic approach to diagnose the root cause and list mitigation steps including quick fixes (increase resources), medium fixes (re-partitioning, two-stage aggregation), and long-term fixes (pre-aggregation, reorganizing data layout).
MediumTechnical
66 practiced
Technical task (SQL + explain): Given this PostgreSQL query using a CTE:
WITH daily AS ( SELECT user_id, DATE(created_at) AS d, COUNT(*) as cnt FROM events WHERE created_at >= '2024-01-01' GROUP BY user_id, DATE(created_at))SELECT d, SUM(cnt) FROM daily GROUP BY d;
Explain how PostgreSQL treats CTEs as optimization fences (in older versions) and propose a rewrite or materialization strategy to improve performance and concurrency when needed.
MediumTechnical
74 practiced
Problem-solving: You need to run a GROUP BY on a column with extremely high cardinality (hundreds of millions distinct keys) for daily metrics. Propose at least five strategies to reduce cost and time: consider approximate algorithms, pre-aggregation, re-keying, sampling, and storage layout changes. Explain trade-offs for accuracy, latency, and complexity.
MediumTechnical
58 practiced
Technical task (SQL): You have monthly partitioned tables orders_2024_01(order_id, customer_id, updated_at), orders_2024_02(...), orders_2024_03(...). Design a SQL query that returns the latest row for each order_id across these monthly partitions. Assume partitions cannot be merged and you should avoid full-table sorts when possible. Show an approach using UNION ALL and window functions or partition pruning.
HardTechnical
79 practiced
Theoretical: Discuss trade-offs between performing deduplication at ingestion time, storing raw append-only data and deduplicating at query time, or maintaining a canonical deduped table. Consider costs (storage, compute), latency, complexity, and operational burden in large-scale data platforms.

Unlock Full Question Bank

Get access to hundreds of Set Operations and Complex Aggregations interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.