waterWang opened a new pull request, #18546:
URL: https://github.com/apache/dolphinscheduler/pull/18546
## Purpose of the pull request
Fixes #18543
`TaskInstanceMapper#findLastTaskInstances` is supposed to return the
**last** task instance per task code of a workflow instance. It resolves "last"
by joining on the maximum `end_time`:
```sql
join (
select task_code, max(end_time) as max_end_time, workflow_instance_id
from t_ds_task_instance
...
group by task_code
) t_max
on ... and instance.end_time = t_max.max_end_time
```
`end_time` is **not unique**. On MySQL it is `datetime` without fractional
seconds, so when two attempts of the same task share the same `end_time` (e.g.
a task that fails and is retried quickly within the same second), both rows
match `instance.end_time = t_max.max_end_time` and the query returns **two rows
for one task code**.
## What this PR changes
The subquery now additionally selects `max(id) as max_id` (the primary key,
which is strictly increasing), and the join is changed from `instance.end_time
= t_max.max_end_time` to `instance.id = t_max.max_id`. This guarantees exactly
one (the latest) task instance per task code, eliminating the duplicate rows.
## Verification
- Query now returns at most one row per `task_code` per
`workflow_instance_id`.
- No behavior change for the common case where `end_time` values are
distinct.
Closes #18543
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]