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.
This commit is contained in:
Mark Travis
2015-04-23 13:01:07 -07:00
committed by Vinnie Falco
parent 5a3168c9ff
commit 5b0109055d
4 changed files with 12 additions and 17 deletions

View File

@@ -4496,6 +4496,8 @@
</ClCompile>
<ClInclude Include="..\..\src\soci\src\core\values.h">
</ClInclude>
<ClInclude Include="..\..\src\soci\src\core\version.h">
</ClInclude>
<ClInclude Include="..\..\src\sqlite\sqlite.h">
</ClInclude>
<ClCompile Include="..\..\src\sqlite\sqlite.unity.c">

View File

@@ -5274,6 +5274,9 @@
<ClInclude Include="..\..\src\soci\src\core\values.h">
<Filter>soci\src\core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\soci\src\core\version.h">
<Filter>soci\src\core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\sqlite\sqlite.h">
<Filter>sqlite</Filter>
</ClInclude>

View File

@@ -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

View File

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