Pair your devices with a code and playback position follows you: pause on this device, hit resume on the other. Position is saved to the site every minute and on pause.
Open this panel on your other device and enter the same code.
Starts this lesson and continues through 9 more to the end of the course.
Both engines bill or bottleneck on bytes touched. Athena charges per byte scanned; Redshift spends slices and memory on blocks it cannot skip. The Athena pricing page's worked example (verified 2026-10-30) is the lesson in miniature: a 3 TB CSV query costs "3 * $5/TB = $15"; gzip it 3:1 and it's $5; store it as Parquet and read one of four columns and it's "0.25 * $5/TB = $1.25". Twelve-to-one, same SQL. Interviewers want you reasoning about layout before syntax.
What the posting is really asking. "Design and optimize queries in Amazon Athena for analytical
workloads" means: can you cut bytes scanned (partitions, projection, columnar, compression), can you
cap spend (workgroups), and do you know the service's hard edges (quotas, the 100-partition INSERT
limit). "Manage data warehouse solutions in Amazon Redshift including data modeling and performance
tuning" means: distribution and sort keys, the maintenance loop (VACUUM/ANALYZE), WLM, and reading
the system tables when a query is slow. Lesson 05 of languages/SQL0-foundations ("Redshift is not
PostgreSQL") already covers unenforced constraints and dialect traps — this lesson assumes it and
does not repeat it.
From aws.amazon.com/athena/pricing (verified 2026-10-30): "You are charged for the number of bytes scanned per query, rounded up to the nearest megabyte, with a 10 MB minimum per query. There are no charges for Data Definition Language (DDL) statements ... or failed queries. Canceled queries are billed for the total amount of data scanned when the query is canceled." The alternative is Capacity Reservations: per-DPU-hour, "no charges for data scanned".
Normal partitions live in the Glue Data Catalog and Athena calls GetPartitions before pruning;
"If a table has a large number of partitions, using GetPartitions can affect performance
negatively" (partition-projection).
Partition projection replaces that call with table properties Athena evaluates in memory, and
"Enabling partition projection on a table causes Athena to ignore any partition metadata registered
to the table". The documented month example
(supported types):
'projection.month.type'='date',
'projection.month.format'='yyyy-MM',
'projection.month.interval'='1',
'projection.month.interval.unit'='MONTHS',
'projection.month.range'='2015-01,NOW',
plus projection.enabled='true'; a custom path uses storage.location.template. Types are
enum, integer, date, injected. ⚠️ Forget one column and you get
HIVE_METASTORE_ERROR: ... is configured for partition projection, but the following partition columns are missing projection configuration.
The performance guide (data optimization) adds three rules people skip: "Athena requires partition keys to be of type STRING in order to push down partition filtering into AWS Glue"; equality predicates on all partition keys run fastest; and "Avoid using MSCK REPAIR TABLE for partition maintenance". Hard ceiling: Athena "cannot read more than 1 million partitions in a single scan" (service-limits).
| Decision | Doc guidance (verified 2026-10-30) |
|---|---|
| Format | Parquet/ORC; default row group 128 MB, ORC stripe 64 MB; don't go smaller |
| Small files | "the overhead of the columnar file format outweighs the benefits" |
| Compression | gzip = wide support; zstd = "good balance between performance and compression ratio" |
| Default write compression | GZIP for Hive Parquet/text; ZLIB for ORC; ZSTD (level 3) for Iceberg |
| Cannot write | Parquet with LZ4 or LZO (reads only) |
| Bucketing | For single-value lookups on high-cardinality keys; worse when querying many values |
Compressed text (gzip CSV/JSON) cannot be split, so "the number of files is the limit for how many workers can process the query".
CREATE TABLE table_name
[ WITH ( property_name = expression [, ...] ) ]
AS query
[ WITH [ NO ] DATA ]
Properties: format, partitioned_by = ARRAY[...], bucketed_by/bucket_count,
write_compression, external_location, table_type = 'ICEBERG'. Partition columns must be
last in the SELECT list. external_location must point at an empty prefix ("Athena never
attempts to delete your data") and fails in a workgroup that enforces a results location.
⚠️ INSERT INTO "supports writing a maximum of 100 partitions to the destination table" per statement, and "is not supported on bucketed tables". The documented workaround is CTAS plus batched INSERTs.
A workgroup carries a per-query limit (BytesScannedCutoffPerQuery, "Minimum value of
10000000" bytes — API)
that cancels the offending query, and workgroup-wide hourly/daily limits that fire an SNS alarm
and can invoke Lambda or disable the workgroup
(control limits).
⚠️ "Canceled queries are charged", and partial results are left in S3 — set a lifecycle rule to
abort incomplete multipart uploads.
Engine version is per workgroup; workgroups "are configured to auto upgrade" by default, and a pinned version is still force-upgraded "when a version is no longer available" (engine-versions). Test in a separate workgroup first.
Result reuse (reusing-query-results): same workgroup only, SELECT/EXECUTE only, default age 60 minutes, maximum 7 days, disabled if you override the result configuration. Reused results scan zero bytes.
Athena engine 3 supports Iceberg 1.4.2 with Parquet, ORC and Avro files; record-level insert,
update, delete, time travel; Glue catalog only with Glue optimistic locking
(querying-iceberg).
Maintenance is yours: OPTIMIZE iceberg_table REWRITE DATA USING BIN_PACK compacts; VACUUM
"performs snapshot expiration and orphan file removal"
(optimization).
⚠️ Lake Formation cannot manage permissions for VACUUM, MERGE, UPDATE, OPTIMIZE on Iceberg.
| Quota | Default | Adjustable |
|---|---|---|
| Active DML queries | us-east-1: 200; most large Regions 100–150; others 20 | Yes |
| Active DDL queries | 20 | Yes |
| DML query timeout | 30 min (user guide: up to 240) | Yes |
| DDL query timeout | 600 min | No |
| Workgroups per account | 1,000 | No |
| Query string length | 262,144 bytes | No |
StartQueryExecution rate |
100/s large Regions, 20/s others | Yes |
Active-query quotas "include both running and queued queries"; exceeding them is
TooManyRequestsException.
GetQueryExecution → Statistics.DataScannedInBytes. Bytes are the cost and the time.SELECT * over wide Parquet? Prune columns.RA3 "with managed storage enable[s] you to optimize your data warehouse by scaling and paying for compute and managed storage independently"; hot data on local SSD, the rest offloaded to S3 (working-with-clusters). DC2 is recommended "for datasets under 1 TB (compressed)". The newer RG family is Graviton-based with an "integrated data lake query engine" (no Spectrum needed). RA3 specs:
| Node | vCPU | RAM GiB | Slices | Managed storage/node | Nodes |
|---|---|---|---|---|---|
| ra3.xlplus (multi) | 4 | 32 | 2 | 32 TB | 2–16 |
| ra3.4xlarge | 12 | 96 | 4 | 128 TB | 2–32 |
| ra3.16xlarge | 48 | 384 | 16 | 128 TB | 2–128 |
Serverless bills RPU-hours per second with a 60-second minimum; 1 RPU = 16 GB; default base capacity 128 RPUs; concurrency scaling and Spectrum are included (serverless-considerations, pricing). Serverless for spiky or unknown load; provisioned RA3 for manual WLM queues, reserved pricing, or predictable 24/7 load.
| Style | Behaviour (c_choosing_dist_sort) |
|---|---|
| AUTO (default) | Small table → ALL; grows → KEY on the PK; no suitable column → EVEN. Background, "minimal impact" |
| EVEN | Round-robin; for tables not in joins |
| KEY | Rows with equal key on the same slice; co-locates joins when both sides use the join key |
| ALL | Full copy on every node; storage × nodes; "only for relatively slow moving tables" |
Docs recommend DISTSTYLE AUTO and SORTKEY AUTO. Sort keys matter because Redshift stores "1 MB
disk blocks" with min/max metadata: a one-month range over five years of date-sorted data can
"remove up to 98 percent of the disk blocks". COMPOUND is the default and the right choice when you
INSERT/UPDATE/DELETE regularly; INTERLEAVED weights every column equally, max eight columns, needs
VACUUM REINDEX, and ⚠️ concurrency scaling "doesn't support queries on tables that use
interleaved sort keys". Check what AUTO did: SVL_AUTO_WORKER_ACTION, SVV_ALTER_TABLE_RECOMMENDATIONS.
ENCODE AUTO is the default; specifying any column encoding turns it off. Defaults when it's off:
sort key columns → RAW; SMALLINT/INTEGER/BIGINT/DECIMAL/DATE/TIMESTAMP/TIMESTAMPTZ → AZ64; CHAR/VARCHAR
→ LZO (encodings).
Leave AUTO on unless you have measured otherwise.
VACUUM [ FULL | SORT ONLY | DELETE ONLY | REINDEX | RECLUSTER ]
[ [ table_name ] [ TO threshold PERCENT ] [ BOOST ] [ FORCE ] ]
"Amazon Redshift automatically sorts data and runs VACUUM DELETE in the background"; FULL is the
default and skips the sort phase for tables ≥ 95% sorted
(VACUUM). Automatic analyze
is on by default (auto_analyze), COPY analyses on load, and the threshold is
analyze_threshold_percent = 10
(analyze). ⚠️ VACUUM without
table permission "completes successfully but has no effect". Decide using SVV_TABLE_INFO:
unsorted, stats_off (0 current, 100 stale), skew_rows, vacuum_sort_benefit.
auto; default one extra cluster, cap via
max_concurrency_scaling_clusters (quota 10, adjustable); "up to one hour of free ... credits per
day", accruing to 30 hours; one-minute minimum when billed. Writes supported on RA3/RG only.SVL_S3PARTITION for qualified partitions
(performance).REFRESH MATERIALIZED VIEW applies base-table changes; auto refresh runs
"when cluster resources are available"; automatic query rewrite uses an MV only if it is current
(MV overview).The General Reference page for Redshift only links to the Management Guide quota table.
| Quota | Default | Adjustable |
|---|---|---|
| Nodes per account | 200 | Yes |
| RA3 nodes in a cluster | 128 | Yes |
| Connections, RA3 cluster | 2,000 | No ("hard limit") |
| Tables, ra3.4xlarge / 16xlarge | 200,000 | No |
| Tables, ra3.xlplus multi-node | 20,000 | No |
| Schemas per database | 9,900 | No |
| Manual WLM slots (all queues) | 50 | No |
| Concurrency scaling clusters | 10 | Yes |
| Serverless workgroups / namespaces | 25 / 25 | Yes |
| Serverless base RPUs per account | greater of 3,200 or 1.5× prior six-month max | — |
-- 1. Find it
select query, elapsed, aborted, substring from svl_qlog order by starttime desc limit 20;
-- (or SYS_QUERY_HISTORY: queue_time, execution_time, result_cache_hit, error_message)
-- 2. Queued or executing?
select service_class, total_queue_time, total_exec_time from stl_wlm_query where query = <id>;
-- 3. What the planner complained about
select event, solution from stl_alert_event_log where query = <id>;
-- 4. Table health
select "table", unsorted, stats_off, skew_rows, vacuum_sort_benefit from svv_table_info;
Alerts map to fixes: Missing statistics → ANALYZE; Nested loop → missing join predicate; Very
selective filter → wrong sort key; Excessive ghost rows → VACUUM; Large distribution / broadcast
(> 1,000,000 rows) → distribution key; Serial execution (DS_DIST_ALL_INNER) → stop
ALL-distributing the big table. ⚠️ STL_ALERT_EVENT_LOG excludes queries that ran on concurrency
scaling clusters.
INSERT INTO ... SELECT over 18 months of daily partitions fails. Why, and what do you do?DS_DIST_ALL_INNER. What happened and what's the fix?SVV_TABLE_INFO shows unsorted 40 and stats_off 2. Which maintenance op matters?vacuum_sort_benefit first; auto-sort may already be handling it.SELECT on CSV, CTAS to Parquet + ZSTD, rerun, compare DataScannedInBytes.svv_table_info before/after a large DELETE and VACUUM; then stl_alert_event_log on a deliberately unjoined pair of tables.