diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java index c172380178..4ac4391e90 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcLogRepository.java @@ -350,7 +350,10 @@ public Integer purge(Execution execution) { DSLContext context = DSL.using(configuration); return context.delete(this.jdbcRepository.getTable()) - .where(field("execution_id", String.class).eq(execution.getId())) + // The deleted field is not used, so ti will always be false. + // We add it here to be sure to use the correct index. + .where(field("deleted", Boolean.class).eq(false)) + .and(field("execution_id", String.class).eq(execution.getId())) .execute(); }); } diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java index d920a0ebe0..1ed0d7438a 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcMetricRepository.java @@ -150,7 +150,10 @@ public Integer purge(Execution execution) { DSLContext context = DSL.using(configuration); return context.delete(this.jdbcRepository.getTable()) - .where(field("execution_id", String.class).eq(execution.getId())) + // The deleted field is not used, so ti will always be false. + // We add it here to be sure to use the correct index. + .where(field("deleted", Boolean.class).eq(false)) + .and(field("execution_id", String.class).eq(execution.getId())) .execute(); }); } @@ -168,8 +171,7 @@ private List queryDistinct(String tenantId, Condition condition, String .getDslContextWrapper() .transactionResult(configuration -> { DSLContext context = DSL.using(configuration); - SelectConditionStep> select = DSL - .using(configuration) + SelectConditionStep> select = context .selectDistinct(field(field)) .from(this.jdbcRepository.getTable()) .where(this.defaultFilter(tenantId)); @@ -185,8 +187,7 @@ private ArrayListTotal query(String tenantId, Condition condition, .getDslContextWrapper() .transactionResult(configuration -> { DSLContext context = DSL.using(configuration); - SelectConditionStep> select = DSL - .using(configuration) + SelectConditionStep> select = context .select(field("value")) .from(this.jdbcRepository.getTable()) .where(this.defaultFilter(tenantId));