ArchiveTask list-unused query optimization (#4600)

* ArchiveTask list unused query optimization

* ArchiveTask list unused query optimization
This commit is contained in:
Egor Riashin 2017-07-26 20:51:20 +03:00 committed by Roman Leventov
parent 684cfbf889
commit 2005c5532f
1 changed files with 5 additions and 1 deletions

View File

@ -928,10 +928,14 @@ public class IndexerSQLMetadataStorageCoordinator implements IndexerMetadataStor
@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()
)
)