Warehouse Autosuspend Summary
MediumSimulation · Snowflake
A cloud warehouse runs queries and suspends itself when it has been idle for a while. You are given queries, a list of [start, duration] pairs sorted by start (non-decreasing), and an integer suspend_after.
Rules:
- The warehouse starts suspended. A query that arrives while it is suspended makes it resume at that query's
start. - A query occupies the warehouse from
starttostart + duration. Queries may overlap; the warehouse is busy while at least one query is running. - When the warehouse becomes idle at time
t(no query running), it suspends at timet + suspend_afterunless another query starts at or beforet + suspend_after. A query starting exactly att + suspend_afterkeeps it running without a resume. - After the last query finishes, the warehouse idles for
suspend_afterseconds and then suspends.
Return [resume_count, running_seconds], where running_seconds is the total time the warehouse was not suspended (from each resume until the following suspend, including busy time and idle time).
Example 1
- Input:
- queries = [[0, 4], [2, 5], [9, 1], [20, 3]], suspend_after = 3
- Output:
- [2, 19]
- Explanation
- The first two queries overlap and keep the warehouse busy from 0 to 7. The query at 9 arrives within the 3-second idle window (which would end at 10), so the warehouse stays up and is idle again at 10, scheduled to suspend at 13. The query at 20 comes later, so the first run lasts 0 to 13 (13 seconds) and a second resume covers 20 to 26 (6 seconds): 2 resumes, 19 seconds.
Example 2
- Input:
- queries = [[0, 2], [5, 1]], suspend_after = 3
- Output:
- [1, 9]
- Explanation
- The warehouse is idle from 2 and would suspend at 5, but a query arrives exactly at 5, which keeps it running. It finishes at 6 and suspends at 9: 1 resume and 9 running seconds.
Example 3
- Input:
- queries = [], suspend_after = 5
- Output:
- [0, 0]
- Explanation
- Nothing ever arrives, so the warehouse never resumes.
Constraints
0 <= queries.length <= 10^50 <= start <= 10^9, andqueriesis sorted bystart1 <= duration <= 10^60 <= suspend_after <= 10^6