Skip to content

Commit

Permalink
Fix dbcheck orphaned path entries performance issue
Browse files Browse the repository at this point in the history
A previous commit introduced performance issues when using the
bareos-dbcheck orphaned path detection. The underlying SQL query
was changed now by using the PathHierarchy table for protecting
Path entries used by BVFS.
  • Loading branch information
sduehr committed May 3, 2018
1 parent 498d855 commit a8f2a39
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
13 changes: 6 additions & 7 deletions src/cats/dml/0072_get_orphaned_paths_0
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#
# dbcheck: eliminate_orphaned_path_records
#
# get all Paths not used by Files
# and are not substrings to others Paths.
# get all Paths not used by Files or BVFS
#
# LIKE: _% wildcard, but at least one character
#
SELECT DISTINCT ParentPath.PathId,File.PathId,ParentPath.Path
FROM Path AS ParentPath LEFT OUTER JOIN File USING(PathId)
SELECT DISTINCT Path.PathId, File.PathId, Path.Path
FROM Path
LEFT JOIN File USING (PathId)
LEFT JOIN PathHierarchy ON (Path.Pathid = PathHierarchy.PPathId)
WHERE File.PathId IS NULL
AND NOT EXISTS (SELECT 1 FROM Path WHERE Path LIKE ParentPath.Path || '_%%')
AND PathHierarchy.PPathId IS NULL
LIMIT 300000
13 changes: 0 additions & 13 deletions src/cats/dml/0072_get_orphaned_paths_0.mysql

This file was deleted.

10 changes: 6 additions & 4 deletions src/cats/mysql_queries.inc
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,13 @@ const char *B_DB_MYSQL::query_definitions[] = {
"WHERE Log.JobId=%s "
,

/* 0072_get_orphaned_paths_0.mysql */
"SELECT DISTINCT ParentPath.PathId,File.PathId,ParentPath.Path "
"FROM Path AS ParentPath LEFT OUTER JOIN File USING(PathId) "
/* 0072_get_orphaned_paths_0 */
"SELECT DISTINCT Path.PathId, File.PathId, Path.Path "
"FROM Path "
"LEFT JOIN File USING (PathId) "
"LEFT JOIN PathHierarchy ON (Path.Pathid = PathHierarchy.PPathId) "
"WHERE File.PathId IS NULL "
"AND NOT EXISTS (SELECT 1 FROM Path WHERE Path LIKE CONCAT(ParentPath.Path,'_%%')) "
"AND PathHierarchy.PPathId IS NULL "
"LIMIT 300000 "
,

Expand Down
8 changes: 5 additions & 3 deletions src/cats/postgresql_queries.inc
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,12 @@ const char *B_DB_POSTGRESQL::query_definitions[] = {
,

/* 0072_get_orphaned_paths_0 */
"SELECT DISTINCT ParentPath.PathId,File.PathId,ParentPath.Path "
"FROM Path AS ParentPath LEFT OUTER JOIN File USING(PathId) "
"SELECT DISTINCT Path.PathId, File.PathId, Path.Path "
"FROM Path "
"LEFT JOIN File USING (PathId) "
"LEFT JOIN PathHierarchy ON (Path.Pathid = PathHierarchy.PPathId) "
"WHERE File.PathId IS NULL "
"AND NOT EXISTS (SELECT 1 FROM Path WHERE Path LIKE ParentPath.Path || '_%%') "
"AND PathHierarchy.PPathId IS NULL "
"LIMIT 300000 "
,

Expand Down
8 changes: 5 additions & 3 deletions src/cats/sqlite_queries.inc
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,12 @@ const char *B_DB_SQLITE::query_definitions[] = {
,

/* 0072_get_orphaned_paths_0 */
"SELECT DISTINCT ParentPath.PathId,File.PathId,ParentPath.Path "
"FROM Path AS ParentPath LEFT OUTER JOIN File USING(PathId) "
"SELECT DISTINCT Path.PathId, File.PathId, Path.Path "
"FROM Path "
"LEFT JOIN File USING (PathId) "
"LEFT JOIN PathHierarchy ON (Path.Pathid = PathHierarchy.PPathId) "
"WHERE File.PathId IS NULL "
"AND NOT EXISTS (SELECT 1 FROM Path WHERE Path LIKE ParentPath.Path || '_%%') "
"AND PathHierarchy.PPathId IS NULL "
"LIMIT 300000 "
,

Expand Down

0 comments on commit a8f2a39

Please sign in to comment.