Warehouse · easy · ~10 min
The weekly customer-ranking query went from 4 minutes to 52. The profile shows a giant window function — ROW_NUMBER() OVER (ORDER BY lifetime_value DESC) across the ENTIRE 1.2B-row customer_events rollup — spilling 210GB to local disk and 84GB to remote storage. The team's proposed fix: 'run it on a 4XL'.
ROW_NUMBER() OVER (ORDER BY lifetime_value DESC)
There's a cheaper order of operations. Find it.