Skip to content

Commit 3c17501

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 2bd5b84 commit 3c17501

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/JdbcStepExecutionDao.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* @author Mahmoud Ben Hassine
6767
* @author Baris Cubukcuoglu
6868
* @author Minsoo Kim
69+
* @author Yanming Zhou
6970
* @see StepExecutionDao
7071
*/
7172
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
@@ -86,12 +87,12 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
8687
private static final String GET_RAW_STEP_EXECUTIONS = """
8788
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
8889
FROM %PREFIX%STEP_EXECUTION
89-
WHERE JOB_EXECUTION_ID = ?
9090
""";
9191

92-
private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS + " ORDER BY STEP_EXECUTION_ID";
92+
private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS
93+
+ " WHERE JOB_EXECUTION_ID = ? ORDER BY STEP_EXECUTION_ID";
9394

94-
private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " AND STEP_EXECUTION_ID = ?";
95+
private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " WHERE STEP_EXECUTION_ID = ?";
9596

9697
private static final String GET_LAST_STEP_EXECUTION = """
9798
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
@@ -325,7 +326,7 @@ private String truncateExitDescription(String description) {
325326
@Nullable
326327
public StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId) {
327328
List<StepExecution> executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
328-
new StepExecutionRowMapper(jobExecution), jobExecution.getId(), stepExecutionId);
329+
new StepExecutionRowMapper(jobExecution), stepExecutionId);
329330

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

0 commit comments

Comments
 (0)