Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Optimizing Redshift Performance
00:00
5 left

Optimizing Redshift Performance

HardSQL · PostgreSQL

Problem

How do you optimize query performance and manage storage costs in Amazon Redshift?

Using the supplied query history, table usage, and storage metadata, write a SQL query that identifies tables requiring optimization attention. Consider completed queries executed during January 2025 and include tables with no qualifying query activity.

Output

  1. One row per stored table with table_name, query_count, total_runtime_ms, avg_runtime_ms, storage_mb, and optimization_priority.
  2. Classify priority as HIGH, MEDIUM, or LOW using runtime, storage, dead-space, and unused-table signals.
  3. Order by total runtime descending, then storage size descending.

Schema

query_log
ColumnTypeDescription
query_idPKINTUnique query identifier
executed_atTIMESTAMPQuery execution timestamp
runtime_msINTQuery runtime in milliseconds
statusVARCHAR(20)Query completion status
query_table_usage
ColumnTypeDescription
query_idINTReferenced query identifier
table_idINTReferenced table identifier
table_storage
ColumnTypeDescription
table_idPKINTUnique table identifier
table_nameVARCHAR(100)Stored table name
total_bytesBIGINTTotal storage consumed in bytes
dead_bytesBIGINTEstimated reclaimable or dead storage in bytes
Tablesquery_logquery_table_usagetable_storage
Interviewer

Your question is Optimizing Redshift Performance. 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.