A Data Engineer is investigating skewed execution in a query that aggregates 10 billion rows by PRODUCT_CATEGORY. The Query Profile shows that one thread processed 6.2 billion rows while all other threads processed between 200–400 million rows each. The PRODUCT_CATEGORY column has only 4 distinct values, and one category represents 62% of all rows. Which TWO strategies are MOST effective for remediating this data skew? (Select TWO.)
- A. Enable query acceleration service (QAS) on the warehouse, which offloads disproportionate partition workloads to a separate serverless compute tier
- B. Convert the aggregation to use APPROXIMATE_COUNT_DISTINCT instead of COUNT(*) to reduce the memory footprint of the large group
- C. Apply a selective filter on the skewed category value first, process it in a separate query, and UNION ALL the results with the remaining categories✓ Correct
- D. Add a salting column by appending a random suffix (e.g., PRODUCT_CATEGORY || '_' || (RANDOM() % 10)) to distribute the dominant key across more buckets, then re-aggregate in a second pass✓ Correct
- E. Increase the warehouse size so that each node has more RAM, allowing the dominant partition to fit entirely in memory without spilling
Explanation
When a single GROUP BY key value holds a disproportionate share of data, hash-based aggregation assigns all rows for that key to one thread, causing skew. Two effective strategies:
- Salting: Artificially expanding the key space (appending a random suffix) breaks the dominant bucket into smaller sub-buckets that can be processed in parallel; a second aggregation merges the partial results.
- Divide and conquer: Isolating the dominant category into its own query allows its volume to be processed with full parallelism across partitions, then UNION ALL combines results.
Why the distractors are wrong:
- A larger warehouse reduces spilling but does not fix the fundamental skew; one thread still handles all 6.2B rows.
- QAS helps accelerate specific scan/aggregation patterns but does not redistribute skewed GROUP BY keys across threads.
- APPROXIMATE_COUNT_DISTINCT changes query semantics (approximate vs. exact) and only applies to COUNT DISTINCT, not general aggregation skew.