From c8897ecf9bcf80470bd318f6b5a6c5ec0f6d5943 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 24 May 2021 19:52:20 +0100 Subject: [PATCH] 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. --- .../org/qortal/repository/hsqldb/HSQLDBATRepository.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java index 8193c5d2..c21dbf8c 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBATRepository.java @@ -542,9 +542,9 @@ public class HSQLDBATRepository implements ATRepository { public List 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 atStates = new ArrayList<>();