Browse Source

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.
pull/37/head
CalDescent 3 years ago
parent
commit
c8897ecf9b
  1. 6
      src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java

6
src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java

@ -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<>();

Loading…
Cancel
Save