Fix slow SQL query in HSQLDBATRepository.getBlockATStatesAtHeight() - mostly used during orphaning

This commit is contained in:
catbref 2020-11-10 16:58:24 +00:00
parent 3ef8b81e51
commit a310e751bb

View File

@ -374,9 +374,10 @@ public class HSQLDBATRepository implements ATRepository {
@Override
public List<ATStateData> getBlockATStatesAtHeight(int height) throws DataException {
String sql = "SELECT AT_address, state_hash, fees, is_initial "
+ "FROM ATStates "
+ "LEFT OUTER JOIN ATs USING (AT_address) "
+ "WHERE height = ? "
+ "FROM ATs "
+ "LEFT OUTER JOIN ATStates "
+ "ON ATStates.AT_address = ATs.AT_address AND height = ? "
+ "WHERE ATStates.AT_address IS NOT NULL "
+ "ORDER BY created_when ASC";
List<ATStateData> atStates = new ArrayList<>();