syncjournaldb: index e2eMangledName column in metadata
authorJan Schmidt <jan@centricular.com>
Thu, 3 Sep 2020 12:51:58 +0000 (22:51 +1000)
committerJan Schmidt <jan@centricular.com>
Thu, 3 Sep 2020 12:56:14 +0000 (22:56 +1000)
Add an index on the e2eMangledName column in the metadata table
to speed up file sync by orders of magnitude on directories with
a large number of files.

Signed-off-by: Jan Schmidt <jan@centricular.com>
src/common/syncjournaldb.cpp

index d13f855d5825b00db0a6ae5df522d7d1d02aee09..1666c4f82b5eac47fa3792b9a4122ddc5009944c 100644 (file)
@@ -745,6 +745,15 @@ bool SyncJournalDb::updateMetadataTableStructure()
         commitInternal("update database structure: add contentChecksum col for uploadinfo");
     }
 
+    if (true) {
+        SqlQuery query(_db);
+        query.prepare("CREATE INDEX IF NOT EXISTS metadata_e2e_id ON metadata(e2eMangledName);");
+        if (!query.exec()) {
+            sqlFail("updateMetadataTableStructure: create index e2eMangledName", query);
+            re = false;
+        }
+        commitInternal("update database structure: add e2eMangledName index");
+    }
 
     return re;
 }