Improve performance of JdbcStepExecutionDao::getLastStepExecution - #4798
Improve performance of JdbcStepExecutionDao::getLastStepExecution#4798quaff wants to merge 1 commit into
JdbcStepExecutionDao::getLastStepExecution#4798Conversation
quaff
commented
Mar 27, 2025
- Use SQL order by clause instead of Java Comparator
- Limit result set size to 1
|
Alternatively, we could use |
|
The suggested change is basically a revert of the fix for #4657. I'm not sure whether the performance gain is worth it, compared to the risk of re-introducing the previous issue. |
This commit will not query all matched rows but only first row. |
It's weird, but I'm OK if this PR is rejected. |
|
I am not a big fan of sorting things on the application side if we can do it on the database side, so this PR has its added value if we do not include any regression or performance degradation as reported in #4657. So basically we moved this from Java to the DB in #891 with 62a8f44, then from the DB to Java in #4657 with 5a62de9, and now back again to the DB with this PR. I could not find the reason we merged #4657, but I guess it was due to this #4657 (comment). I suggested to use
Is using Thoughts?
@hpoettker I agree. I don't know @quaff if you had a chance to benchmark this change? It would be great if we have a baseline to measure the performance improvement/degradation and decide if this change is worth it. |
1. Use SQL order by clause instead of Java Comparator 2. Limit result set size to 1 Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
I think most JDBC drivers honer the max rows.
I didn't, @jpraet could you verify this patch works for you since you reported #4657? |
|
Hi, we have since upgraded from DB2 10 to DB2 11 and I can no longer reproduce the slow query reported in #4657. |
Push the step name filter, ordering (createTime DESC, then stepExecutionId DESC), and limit(1) down to MongoDB instead of fetching all step executions for the job instance and filtering/sorting in Java. This mirrors the optimization applied to the JDBC variant in #4798 and addresses the existing `// TODO optimize the query` marker. Resolves #5385 Signed-off-by: Seonwoo Jung <laborlawseon@kap.kr>