Skip to content

Commit

Permalink
ArchiveTask list-unused query optimization (apache#4600)
Browse files Browse the repository at this point in the history
* ArchiveTask list unused query optimization

* ArchiveTask list unused query optimization
  • Loading branch information
egor-ryashin authored and leventov committed Jul 26, 2017
1 parent 684cfbf commit 2005c55
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,14 @@ public List<DataSegment> getUnusedSegmentsForInterval(final String dataSource, f
@Override
public List<DataSegment> inTransaction(final Handle handle, final TransactionStatus status) throws Exception
{
// 2 range conditions are used on different columns, but not all SQL databases properly optimize it.
// Some databases can only use an index on one of the columns. An additional condition provides
// explicit knowledge that 'start' cannot be greater than 'end'.
return handle
.createQuery(
StringUtils.format(
"SELECT payload FROM %1$s WHERE dataSource = :dataSource and start >= :start and %2$send%2$s <= :end and used = false",
"SELECT payload FROM %1$s WHERE dataSource = :dataSource and start >= :start "
+ "and start <= :end and %2$send%2$s <= :end and used = false",
dbTables.getSegmentsTable(), connector.getQuoteString()
)
)
Expand Down

0 comments on commit 2005c55

Please sign in to comment.