diff --git a/server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java b/server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java index 3cf94d9870d6..c654d5e229b7 100644 --- a/server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java +++ b/server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java @@ -180,15 +180,19 @@ public List> retrieveUsedSegmentsAndCreatedDates(Strin "SELECT created_date, payload FROM %1$s WHERE dataSource = :dataSource AND used = true" ); + final List intervals = new ArrayList<>(); + // Do not need an interval condition if the interval is ETERNITY if (!Intervals.isEternity(interval)) { - SqlSegmentsMetadataQuery.appendConditionForIntervalsAndMatchMode( - queryBuilder, - ImmutableList.of(interval), - SqlSegmentsMetadataQuery.IntervalMode.OVERLAPS, - connector - ); + intervals.add(interval); } + SqlSegmentsMetadataQuery.appendConditionForIntervalsAndMatchMode( + queryBuilder, + intervals, + SqlSegmentsMetadataQuery.IntervalMode.OVERLAPS, + connector + ); + final String queryString = StringUtils.format(queryBuilder.toString(), dbTables.getSegmentsTable()); return connector.retryWithHandle( handle -> { @@ -196,9 +200,7 @@ public List> retrieveUsedSegmentsAndCreatedDates(Strin .createQuery(queryString) .bind("dataSource", dataSource); - if (!Intervals.isEternity(interval)) { - SqlSegmentsMetadataQuery.bindQueryIntervals(query, ImmutableList.of(interval)); - } + SqlSegmentsMetadataQuery.bindQueryIntervals(query, intervals); return query .map((int index, ResultSet r, StatementContext ctx) ->