Skip to content

Commit 9d35868

Browse files
committed
Improve performance of JdbcStepExecutionDao::getStepExecution
`JOB_EXECUTION_ID = ?` in where clause is unnecessary since `STEP_EXECUTION_ID` is primary key. Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent 08c4cb1 commit 9d35868

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
* @author Mahmoud Ben Hassine
6969
* @author Baris Cubukcuoglu
7070
* @author Minsoo Kim
71+
* @author Yanming Zhou
7172
* @see StepExecutionDao
7273
*/
7374
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
@@ -88,12 +89,12 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
8889
private static final String GET_RAW_STEP_EXECUTIONS = """
8990
SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION, CREATE_TIME
9091
FROM %PREFIX%STEP_EXECUTION
91-
WHERE JOB_EXECUTION_ID = ?
9292
""";
9393

94-
private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS + " ORDER BY STEP_EXECUTION_ID";
94+
private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS
95+
+ " WHERE JOB_EXECUTION_ID = ? ORDER BY STEP_EXECUTION_ID";
9596

96-
private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " AND STEP_EXECUTION_ID = ?";
97+
private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " WHERE STEP_EXECUTION_ID = ?";
9798

9899
private static final String GET_LAST_STEP_EXECUTION = """
99100
SELECT SE.STEP_EXECUTION_ID, SE.STEP_NAME, SE.START_TIME, SE.END_TIME, SE.STATUS, SE.COMMIT_COUNT, SE.READ_COUNT, SE.FILTER_COUNT, SE.WRITE_COUNT, SE.EXIT_CODE, SE.EXIT_MESSAGE, SE.READ_SKIP_COUNT, SE.WRITE_SKIP_COUNT, SE.PROCESS_SKIP_COUNT, SE.ROLLBACK_COUNT, SE.LAST_UPDATED, SE.VERSION, SE.CREATE_TIME, JE.JOB_EXECUTION_ID, JE.START_TIME, JE.END_TIME, JE.STATUS, JE.EXIT_CODE, JE.EXIT_MESSAGE, JE.CREATE_TIME, JE.LAST_UPDATED, JE.VERSION
@@ -327,7 +328,7 @@ private String truncateExitDescription(String description) {
327328
@Nullable
328329
public StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId) {
329330
List<StepExecution> executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
330-
new StepExecutionRowMapper(jobExecution), jobExecution.getId(), stepExecutionId);
331+
new StepExecutionRowMapper(jobExecution), stepExecutionId);
331332

332333
Assert.state(executions.size() <= 1,
333334
"There can be at most one step execution with given name for single job execution");

0 commit comments

Comments
 (0)