Rewrite of HSQLDBATRepository.getBlockATStatesAtHeight() SQL query

The previous query was taking almost half a second to run each time, whereas the new version runs 10-100x faster. This was the main bottleneck with block serialization and should therefore allow for much faster syncing once rolled out to the network. Tested several thousand blocks to ensure that the results returned by the new query match those returned by the old one.
This commit is contained in:
CalDescent 2021-05-24 19:52:20 +01:00
parent 2c8b94d469
commit c8897ecf9b

View File

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