From aa5d16b3d82aacfbfba16236b02278be7f473b7d Mon Sep 17 00:00:00 2001 From: Mark Travis Date: Thu, 23 Apr 2015 13:01:07 -0700 Subject: [PATCH] Skip inefficent SQL query (RIPD-870): For large data sets the JOIN may not make forward progress in time. This prevents the deletion of those entries in the database during online delete. The number of such entries is very small compared to the total size of the data anyway. A future version will address this more thoroughly. --- Builds/VisualStudio2013/RippleD.vcxproj | 2 ++ Builds/VisualStudio2013/RippleD.vcxproj.filters | 3 +++ src/ripple/app/data/tests/SociDB.test.cpp | 16 ---------------- src/ripple/app/misc/SHAMapStoreImp.cpp | 8 +++++++- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 1f54b0d61..5f7db0b87 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -4509,6 +4509,8 @@ + + diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 595655c86..f536e4601 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -5280,6 +5280,9 @@ soci\src\core + + soci\src\core + sqlite diff --git a/src/ripple/app/data/tests/SociDB.test.cpp b/src/ripple/app/data/tests/SociDB.test.cpp index c3f9da828..af8c29fbc 100644 --- a/src/ripple/app/data/tests/SociDB.test.cpp +++ b/src/ripple/app/data/tests/SociDB.test.cpp @@ -354,22 +354,6 @@ public: soci::into (validationsLH); expect (ledgersLS.size () == numRows && validationsLH.size () == numRows); - s << "DELETE FROM Validations WHERE LedgerHash IN " - "(SELECT Ledgers.LedgerHash FROM Validations JOIN Ledgers ON " - "Validations.LedgerHash=Ledgers.LedgerHash WHERE " - "Ledgers.LedgerSeq < :num);", - soci::use (numRows / 2); - validationsLH.resize (numRows * 2); - s << "SELECT LedgerHash FROM Validations;", - soci::into (validationsLH); - expect (validationsLH.size () == numRows / 2); - for (auto i = ledgerHashes.begin () + numRows / 2; - i != ledgerHashes.end (); - ++i) - { - expect (find (validationsLH.begin (), validationsLH.end (), *i) - != validationsLH.end ()); - } } using namespace boost::filesystem; // Remove the database diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index 837aa47e0..4ed922e28 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -570,12 +570,18 @@ SHAMapStoreImp::clearPrior (LedgerIndex lastRotated) // TODO This won't remove validations for ledgers that do not get // validated. That will likely require inserting LedgerSeq into - // the validations table + // the validations table. + // + // This query has poor performance with large data sets. + // The schema needs to be redesigned to avoid the JOIN, or an + // RDBMS that supports concurrency should be used. + /* clearSql (*ledgerDb_, lastRotated, "SELECT MIN(LedgerSeq) FROM Ledgers;", "DELETE FROM Validations WHERE LedgerHash IN " "(SELECT Ledgers.LedgerHash FROM Validations JOIN Ledgers ON " "Validations.LedgerHash=Ledgers.LedgerHash WHERE Ledgers.LedgerSeq < %u);"); + */ if (health()) return;