Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.