mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
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.
This commit is contained in:
parent
7fcf723039
commit
b09498d852
2 changed files with 16 additions and 4 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -331,11 +331,20 @@ 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue