You are given a table async_functions that contains function execution records and their completion times. Each function has an execution_id, function_name, original_completion_time (in milliseconds), and a delay_ms value that represents additional delay to be added.
Task: Write a SQL query to calculate the delayed completion time for each function by adding the delay_ms to the original_completion_time. Return the results ordered by the delayed completion time to preserve the execution sequence.
The query should return:
execution_idfunction_nameoriginal_completion_timedelayed_completion_time(calculated as original_completion_time + delay_ms)
Table Schema
| Column Name | Type | Description |
|---|---|---|
execution_id
PK
|
int | Unique identifier for each function execution |
function_name
|
varchar | Name of the async function |
original_completion_time
|
int | Original completion time in milliseconds |
delay_ms
|
int | Additional delay in milliseconds to be added |
Input & Output
| execution_id | function_name | original_completion_time | delay_ms |
|---|---|---|---|
| 1 | fetchData | 100 | 50 |
| 2 | saveUser | 200 | 100 |
| 3 | sendEmail | 80 | 40 |
| execution_id | function_name | original_completion_time | delayed_completion_time |
|---|---|---|---|
| 3 | sendEmail | 80 | 120 |
| 1 | fetchData | 100 | 150 |
| 2 | saveUser | 200 | 300 |
Each function gets its delay added to the original completion time. Results are ordered by delayed completion time: sendEmail (80+40=120), fetchData (100+50=150), saveUser (200+100=300).
| execution_id | function_name | original_completion_time | delay_ms |
|---|---|---|---|
| 1 | quickTask | 50 | 0 |
| 2 | slowTask | 300 | 25 |
| execution_id | function_name | original_completion_time | delayed_completion_time |
|---|---|---|---|
| 1 | quickTask | 50 | 50 |
| 2 | slowTask | 300 | 325 |
When delay_ms is 0, the delayed completion time equals the original completion time. quickTask has no additional delay (50+0=50), while slowTask gets 25ms delay (300+25=325).
Constraints
-
1 ≤ execution_id ≤ 1000 -
1 ≤ original_completion_time ≤ 10000 -
0 ≤ delay_ms ≤ 5000 -
function_nameis a non-empty string