[Pkg-owncloud-commits] [owncloud-client] 32/115: csync journal: Improve get_below_path query.

Sandro Knauß hefee-guest at moszumanska.debian.org
Fri Aug 29 22:03:57 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit b09498d852ca21801aa05e14314e28de209cc950
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Thu Aug 14 13:52:44 2014 +0200

    csync journal: Improve get_below_path query.
    
    Add another index on the pathlen column. Use that column to deselect
    all rows that are shorter than the path to search files below. That
    shrinks the amount of rows to examine using LIKE tremendously by
    a cheaply to query for criteria.
---
 csync/src/csync_statedb.c    |  9 ++++++---
 src/mirall/syncjournaldb.cpp | 11 ++++++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/csync/src/csync_statedb.c b/csync/src/csync_statedb.c
index d04c2d2..0a26f81 100644
--- a/csync/src/csync_statedb.c
+++ b/csync/src/csync_statedb.c
@@ -467,7 +467,7 @@ char *csync_statedb_get_etag( CSYNC *ctx, uint64_t jHash ) {
     return ret;
 }
 
-#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM metadata WHERE path LIKE(?)"
+#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm FROM metadata WHERE pathlen>? AND path LIKE(?)"
 
 int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
     int rc;
@@ -475,6 +475,7 @@ int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
     int64_t cnt = 0;
     char *likepath;
     int asp;
+    int min_path_len;
 
     if( !path ) {
         return -1;
@@ -486,7 +487,7 @@ int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
 
     rc = sqlite3_prepare_v2(ctx->statedb.db, BELOW_PATH_QUERY, -1, &stmt, NULL);
     if( rc != SQLITE_OK ) {
-      CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "WRN: Unable to create stmt for hash query.");
+      CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "WRN: Unable to create stmt for below path query.");
       return -1;
     }
 
@@ -500,7 +501,9 @@ int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
         return -1;
     }
 
-    sqlite3_bind_text(stmt, 1, likepath, -1, SQLITE_STATIC);
+    min_path_len = strlen(path);
+    sqlite3_bind_int(stmt, 1, min_path_len);
+    sqlite3_bind_text(stmt, 2, likepath, -1, SQLITE_STATIC);
 
     cnt = 0;
 
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp
index 89c1238..35a51ba 100644
--- a/src/mirall/syncjournaldb.cpp
+++ b/src/mirall/syncjournaldb.cpp
@@ -331,12 +331,21 @@ bool SyncJournalDb::updateDatabaseStructure()
 
     if( 1 ) {
         QSqlQuery query(_db);
-        query.prepare("CREATE UNIQUE INDEX IF NOT EXISTS metadata_inode ON metadata(inode);");
+        query.prepare("CREATE INDEX IF NOT EXISTS metadata_inode ON metadata(inode);");
         re = re && query.exec();
 
         commitInternal("update database structure: add inode index");
 
     }
+
+    if( 1 ) {
+        QSqlQuery query(_db);
+        query.prepare("CREATE INDEX IF NOT EXISTS metadata_pathlen ON metadata(pathlen);");
+        re = re && query.exec();
+
+        commitInternal("update database structure: add pathlen index");
+
+    }
     return re;
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list