From c31b13353975661967fa7355585765d9e8b66c28 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Fri, 19 Nov 2010 10:34:19 +0100 Subject: [PATCH] Use JobTDate instead of StartTime, and sort by JobTDate instead of JobId --- bacula/src/cats/sql_cmds.c | 12 +++++++----- bacula/src/cats/sql_get.c | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index b0070cc63f..3acb53b7e5 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -292,7 +292,8 @@ const char *uar_jobid_fileindex_from_table = */ const char *select_recent_version_with_basejob_default = "SELECT FileId, Job.JobId AS JobId, FileIndex, File.PathId AS PathId, " - "File.FilenameId AS FilenameId, LStat, MD5, MarkId " + "File.FilenameId AS FilenameId, LStat, MD5, MarkId, " + "Job.JobTDate AS JobTDate" "FROM Job, File, ( " "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " "FROM ( " @@ -321,7 +322,7 @@ const char *select_recent_version_with_basejob[5] = { select_recent_version_with_basejob_default, /* Postgresql */ /* The DISTINCT ON () permits to avoid extra join */ - "SELECT DISTINCT ON (FilenameId, PathId) StartTime, JobId, FileId, " + "SELECT DISTINCT ON (FilenameId, PathId) JobTDate, JobId, FileId, " "FileIndex, PathId, FilenameId, LStat, MD5, MarkId " "FROM " "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5, MarkId " @@ -332,7 +333,7 @@ const char *select_recent_version_with_basejob[5] = { "FROM BaseFiles JOIN File USING (FileId) " "WHERE BaseFiles.JobId IN (%s) " ") AS T JOIN Job USING (JobId) " - "ORDER BY FilenameId, PathId, StartTime DESC ", + "ORDER BY FilenameId, PathId, JobTDate DESC ", /* SQLite */ select_recent_version_with_basejob_default, @@ -361,7 +362,8 @@ const char *select_recent_version_with_basejob[5] = { */ const char *select_recent_version_with_basejob_and_delta_default = "SELECT FileId, Job.JobId AS JobId, FileIndex, File.PathId AS PathId, " - "File.FilenameId AS FilenameId, LStat, MD5, MarkId " + "File.FilenameId AS FilenameId, LStat, MD5, MarkId, " + "Job.JobTDate AS JobTDate " "FROM Job, File, ( " "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId, MarkId " "FROM ( " @@ -419,7 +421,7 @@ const char *select_recent_version_with_basejob_and_delta[5] = { const char *select_recent_version_default = "SELECT j1.JobId AS JobId, f1.FileId AS FileId, f1.FileIndex AS FileIndex, " "f1.PathId AS PathId, f1.FilenameId AS FilenameId, " - "f1.LStat AS LStat, f1.MD5 AS MD5 " + "f1.LStat AS LStat, f1.MD5 AS MD5, j1.JobTDate " "FROM ( " /* Choose the last version for each Path/Filename */ "SELECT max(JobTDate) AS JobTDate, PathId, FilenameId " "FROM File JOIN Job USING (JobId) " diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 069fb0b321..bd440dd350 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1116,8 +1116,8 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, "JOIN Filename ON (Filename.FilenameId = T1.FilenameId) " "JOIN Path ON (Path.PathId = T1.PathId) " "WHERE FileIndex > 0 " -"ORDER BY T1.JobId, FileIndex ASC",/* Return sorted by JobId, */ - /* FileIndex for restore code */ +"ORDER BY T1.JobTDate, FileIndex ASC",/* Return sorted by JobId, */ + /* FileIndex for restore code */ buf2.c_str()); Dmsg1(100, "q=%s\n", buf.c_str()); #else -- 2.39.5