Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimizing Cloud Warehouse Queries
00:00
5 left

Optimizing Cloud Warehouse Queries

HardSQL · PostgreSQL

Problem

How do you optimize query performance for massive datasets in a cloud-based warehouse?

Using the provided execution, warehouse, and scan tables, write one PostgreSQL query that efficiently summarizes successful executions during Q1 2025. Include only query fingerprints ranked in the top two by total bytes scanned within each warehouse and month.

Output

  1. One row per warehouse, month, and included query fingerprint.
  2. Columns: warehouse_name, region, month_start, query_fingerprint, execution_count, total_elapsed_ms, total_bytes_scanned, total_rows_scanned, and performance_rank.
  3. Sort by warehouse name, month, rank, and query fingerprint.

Schema

query_executions
ColumnTypeDescription
execution_idPKINTUnique query execution identifier
warehouse_idINTWarehouse that executed the query
query_fingerprintVARCHAR(64)Normalized query identifier
started_atTIMESTAMPQuery start timestamp
statusVARCHAR(16)Execution status
elapsed_msBIGINTElapsed execution time in milliseconds
bytes_scannedBIGINTBytes scanned by the execution
warehouse_clusters
ColumnTypeDescription
warehouse_idPKINTUnique warehouse identifier
warehouse_nameVARCHAR(80)Warehouse display name
regionVARCHAR(40)Cloud region
cluster_sizeVARCHAR(20)Configured cluster size
query_table_scans
ColumnTypeDescription
scan_idPKINTUnique table scan record
execution_idINTRelated query execution
table_nameVARCHAR(120)Table accessed by the execution
rows_scannedBIGINTRows scanned from the table
Tablesquery_executionswarehouse_clustersquery_table_scans
Interviewer

Your question is Optimizing Cloud Warehouse Queries. Start with the requirements and the three 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.