From: Eric Bollengier Date: Thu, 17 Sep 2009 12:46:22 +0000 (+0200) Subject: Use new query for Mysql and Sqlite for basejob + accurate X-Git-Tag: Release-7.0.0~2626 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d8269aff272819d7cc8b2a4526db14ff3b5f38bb;p=bacula%2Fbacula Use new query for Mysql and Sqlite for basejob + accurate --- diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index b4efefa061..89e5e3b66a 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -453,17 +453,26 @@ const char *uar_jobid_fileindex_from_table = /* Get the list of the last recent version with a given jobid list */ const char *select_recent_version_with_basejob[4] = { /* MySQL */ - "SELECT max(FileId), JobId, FileIndex, PathId, FilenameId, LStat, MD5 " - "FROM " - "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 " - "FROM File WHERE JobId IN (%s) " - "UNION ALL " - "SELECT File.FileId, File.JobId, PathId, FilenameId, " - "File.FileIndex, LStat, MD5 " - "FROM BaseFiles JOIN File USING (FileId) " +"SELECT FileId, Job.JobId, FileIndex, File.PathId, File.FilenameId, LStat, MD5 " +"FROM ( " + "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " + "FROM ( " + "SELECT JobTDate, PathId, FilenameId " + "FROM File JOIN Job USING (JobId) " + "WHERE JobId IN (%s) " + "UNION ALL " + "SELECT JobTDate, PathId, FilenameId " + "FROM BaseFiles " + "JOIN File USING (FileId) " + "JOIN Job ON (BaseJobId = Job.JobId) " "WHERE BaseFiles.JobId IN (%s) " - ") AS T " - "GROUP BY PathId, FilenameId ", + ") AS temp GROUP BY PathId, FilenameId " + ") AS T1 " + "JOIN Job, File " +"WHERE Job.JobId IN (%s) " + "AND Job.JobTDate = T1.JobTDate " + "AND File.PathId = T1.PathId " + "AND File.FilenameId = T1.PathId ", /* Postgresql */ "SELECT DISTINCT ON (FilenameId, PathId) StartTime, JobId, FileId, " @@ -480,30 +489,48 @@ const char *select_recent_version_with_basejob[4] = { "ORDER BY FilenameId, PathId, StartTime DESC ", /* SQLite */ - "SELECT max(FileId), JobId, FileIndex, PathId, FilenameId, LStat, MD5 " - "FROM " - "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 " - "FROM File WHERE JobId IN (%s) " - "UNION ALL " - "SELECT File.FileId, File.JobId, PathId, FilenameId, " - "File.FileIndex, LStat, MD5 " - "FROM BaseFiles JOIN File USING (FileId) " +"SELECT FileId, Job.JobId, FileIndex, File.PathId, File.FilenameId, LStat, MD5 " +"FROM ( " + "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " + "FROM ( " + "SELECT JobTDate, PathId, FilenameId " + "FROM File JOIN Job USING (JobId) " + "WHERE JobId IN (%s) " + "UNION ALL " + "SELECT JobTDate, PathId, FilenameId " + "FROM BaseFiles " + "JOIN File USING (FileId) " + "JOIN Job ON (BaseJobId = Job.JobId) " "WHERE BaseFiles.JobId IN (%s) " - ") AS T " - "GROUP BY PathId, FilenameId ", + ") AS temp GROUP BY PathId, FilenameId " + ") AS T1 " + "JOIN Job, File " +"WHERE Job.JobId IN (%s) " + "AND Job.JobTDate = T1.JobTDate " + "AND File.PathId = T1.PathId " + "AND File.FilenameId = T1.PathId ", /* SQLite3 */ - "SELECT max(FileId), JobId, FileIndex, PathId, FilenameId, LStat, MD5 " - "FROM " - "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 " - "FROM File WHERE JobId IN (%s) " - "UNION ALL " - "SELECT File.FileId, File.JobId, PathId, FilenameId, " - "File.FileIndex, LStat, MD5 " - "FROM BaseFiles JOIN File USING (FileId) " +"SELECT FileId, Job.JobId, FileIndex, File.PathId, File.FilenameId, LStat, MD5 " +"FROM ( " + "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " + "FROM ( " + "SELECT JobTDate, PathId, FilenameId " + "FROM File JOIN Job USING (JobId) " + "WHERE JobId IN (%s) " + "UNION ALL " + "SELECT JobTDate, PathId, FilenameId " + "FROM BaseFiles " + "JOIN File USING (FileId) " + "JOIN Job ON (BaseJobId = Job.JobId) " "WHERE BaseFiles.JobId IN (%s) " - ") AS T " - "GROUP BY PathId, FilenameId " + ") AS temp GROUP BY PathId, FilenameId " + ") AS T1 " + "JOIN Job, File " +"WHERE Job.JobId IN (%s) " + "AND Job.JobTDate = T1.JobTDate " + "AND File.PathId = T1.PathId " + "AND File.FilenameId = T1.PathId " }; /* Get the list of the last recent version with a given BaseJob jobid list */