Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated query files for denormalization
- Loading branch information
Showing
16 changed files
with
314 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
# Find JobId, FileIndex for a given path/file and date | ||
# for use when inserting individual files into the tree. | ||
|
||
SELECT Job.JobId, File.FileIndex | ||
FROM Job, File, Path, Filename, Client | ||
WHERE Job.JobId = File.JobId | ||
AND Job.StartTime <= '%s' | ||
AND Path.Path = '%s' | ||
AND Filename.Name = '%s' | ||
AND Client.Name = '%s' | ||
AND Job.ClientId = Client.ClientId | ||
AND Path.PathId = File.PathId | ||
AND Filename.FilenameId = File.FilenameId | ||
AND JobStatus IN ('T','W') | ||
AND Type = 'B' | ||
ORDER BY Job.StartTime DESC LIMIT 1 | ||
SELECT Job.JobId, | ||
File.FileIndex | ||
FROM Job, | ||
FILE, | ||
Path, | ||
Client | ||
WHERE Job.JobId=File.JobId | ||
AND Job.StartTime<='%s' | ||
AND Path.Path='%s' | ||
AND File.Name='%s' | ||
AND Client.Name='%s' | ||
AND Job.ClientId=Client.ClientId | ||
AND Path.PathId=File.PathId | ||
AND JobStatus IN ('T', | ||
'W') | ||
AND TYPE='B' | ||
ORDER BY Job.StartTime DESC | ||
LIMIT 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
SELECT Job.JobId, File.FileIndex | ||
FROM Job, File, Path, Filename, Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId = File.JobId | ||
AND Job.StartTime <= '%s' | ||
AND Path.Path = '%s' | ||
AND Filename.Name = '%s' | ||
AND Client.Name = '%s' | ||
AND Job.ClientId = Client.ClientId | ||
AND Path.PathId = File.PathId | ||
AND Filename.FilenameId = File.FilenameId | ||
ORDER BY Job.StartTime DESC LIMIT 1 | ||
SELECT Job.JobId, | ||
File.FileIndex | ||
FROM Job, | ||
FILE, | ||
Path, | ||
Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId=File.JobId | ||
AND Job.StartTime<='%s' | ||
AND Path.Path='%s' | ||
AND File.Name='%s' | ||
AND Client.Name='%s' | ||
AND Job.ClientId=Client.ClientId | ||
AND Path.PathId=File.PathId | ||
ORDER BY Job.StartTime DESC | ||
LIMIT 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
# Get the list of the last recent version with a given BaseJob jobid list | ||
# We don't handle Delta with BaseJobs, they have only Full files | ||
|
||
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, j1.JobTDate | ||
FROM ( | ||
SELECT max(JobTDate) AS JobTDate, PathId, FilenameId | ||
FROM File | ||
JOIN Job | ||
USING (JobId) | ||
WHERE File.JobId IN (%s) | ||
GROUP BY PathId, FilenameId | ||
) AS t1, Job AS j1, File AS f1 | ||
WHERE t1.JobTDate = j1.JobTDate | ||
AND j1.JobId IN (%s) | ||
AND t1.FilenameId = f1.FilenameId | ||
AND t1.PathId = f1.PathId | ||
AND j1.JobId = f1.JobId | ||
SELECT j1.JobId AS JobId, | ||
f1.FileId AS FileId, | ||
f1.FileIndex AS FileIndex, | ||
f1.PathId AS PathId, | ||
f1.Name AS Name, | ||
f1.LStat AS LStat, | ||
f1.MD5 AS MD5, | ||
j1.JobTDate | ||
FROM | ||
(SELECT max(JobTDate) AS JobTDate, | ||
PathId, | ||
File.Name | ||
FROM FILE | ||
JOIN Job USING (JobId) | ||
WHERE File.JobId IN (%s) | ||
GROUP BY PathId, | ||
File.Name) AS t1, | ||
Job AS j1, | ||
FILE AS f1 | ||
WHERE t1.JobTDate = j1.JobTDate | ||
AND j1.JobId IN (%s) | ||
AND t1.PathId = f1.PathId | ||
AND j1.JobId = f1.JobId | ||
AND t1.Name = f1.Name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
SELECT DISTINCT | ||
ON (FilenameId, PathId) JobTDate, JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 | ||
FROM File | ||
JOIN Job | ||
USING (JobId) | ||
WHERE JobId IN (%s) | ||
ORDER BY FilenameId, PathId, JobTDate DESC | ||
SELECT DISTINCT ON (File.Name, | ||
PathId) JobTDate, | ||
JobId, | ||
FileId, | ||
FileIndex, | ||
PathId, | ||
File.Name, | ||
LStat, | ||
MD5 | ||
FROM FILE | ||
JOIN Job USING (JobId) | ||
WHERE JobId IN (%s) BY File.Name, | ||
PathId, | ||
JobTDate DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
CREATE TEMPORARY TABLE new_basefile%lld AS | ||
SELECT Path.Path AS Path, Filename.Name AS Name, Temp.FileIndex AS FileIndex, Temp.JobId AS JobId, Temp.LStat AS LStat, | ||
Temp.FileId AS FileId, Temp.MD5 AS MD5 | ||
FROM ( %s ) AS Temp | ||
JOIN Filename | ||
USING (FilenameId) | ||
JOIN Path | ||
USING (PathId) | ||
WHERE Temp.FileIndex > 0 | ||
CREATE | ||
TEMPORARY TABLE new_basefile%lld AS | ||
SELECT Path.Path AS Path, | ||
Temp.Name AS Name, | ||
Temp.FileIndex AS FileIndex, | ||
Temp.JobId AS JobId, | ||
Temp.LStat AS LStat, | ||
Temp.FileId AS FileId, | ||
Temp.MD5 AS MD5 | ||
FROM (%s) AS TEMP | ||
JOIN Path ON (Path.PathId = Temp.PathId) | ||
WHERE Temp.FileIndex > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
DECLARE GLOBAL TEMPORARY TABLE new_basefile%lld AS | ||
SELECT Path.Path AS Path, Filename.Name AS Name, Temp.FileIndex AS FileIndex, Temp.JobId AS JobId, Temp.LStat AS LStat, | ||
Temp.FileId AS FileId, Temp.MD5 AS MD5 | ||
FROM ( %s ) AS Temp | ||
JOIN Filename | ||
USING (FilenameId) | ||
JOIN Path | ||
USING (PathId) | ||
WHERE Temp.FileIndex > 0 | ||
ON COMMIT PRESERVE ROWS | ||
WITH NORECOVERY | ||
DECLARE GLOBAL | ||
TEMPORARY TABLE new_basefile%lld AS | ||
SELECT Path.Path AS Path, | ||
Temp.Name AS Name, | ||
Temp.FileIndex AS FileIndex, | ||
Temp.JobId AS JobId, | ||
Temp.LStat AS LStat, | ||
Temp.FileId AS FileId, | ||
Temp.MD5 AS MD5 | ||
FROM (%s) AS TEMP | ||
JOIN Path ON (Path.PathId = Temp.PathId) | ||
WHERE Temp.FileIndex > 0 ON | ||
COMMIT PRESERVE ROWS WITH NORECOVERY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
# List Jobs where a particular file is saved | ||
|
||
SELECT Job.JobId as JobId, Path.Path||Filename.Name as Name, StartTime, Type as JobType, JobStatus, JobFiles, JobBytes | ||
FROM Client, Job, File, Filename, Path | ||
WHERE Client.Name = '%s' | ||
AND Client.ClientId = Job.ClientId | ||
AND Job.JobId = File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId = File.PathId | ||
AND Filename.FilenameId = File.FilenameId | ||
AND Filename.Name = '%s' | ||
ORDER BY StartTime DESC LIMIT 20 | ||
SELECT Job.JobId AS JobId, | ||
Path.Path||File.Name AS Name, | ||
StartTime, | ||
TYPE AS JobType, | ||
JobStatus, | ||
JobFiles, | ||
JobBytes | ||
FROM Client, | ||
Job, | ||
FILE, | ||
Path | ||
WHERE Client.Name='%s' | ||
AND Client.ClientId=Job.ClientId | ||
AND Job.JobId=File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId=File.PathId | ||
AND File.Name='%s' | ||
ORDER BY StartTime DESC | ||
LIMIT 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
SELECT Job.JobId as JobId, Path.Path||Filename.Name as Name, StartTime, Type as JobType, JobStatus, JobFiles, JobBytes | ||
FROM Client, Job, File, Filename, Path | ||
WHERE Client.Name = '%s' | ||
AND Client.ClientId = Job.ClientId | ||
AND Job.JobId = File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId = File.PathId | ||
AND Filename.FilenameId = File.FilenameId | ||
AND Filename.Name = '%s' | ||
ORDER BY StartTime DESC FETCH FIRST 20 ROWS ONLY | ||
SELECT Job.JobId AS JobId, | ||
Path.Path||File.Name AS Name, | ||
StartTime, | ||
TYPE AS JobType, | ||
JobStatus, | ||
JobFiles, | ||
JobBytes | ||
FROM Client, | ||
Job, | ||
FILE, | ||
Path | ||
WHERE Client.Name='%s' | ||
AND Client.ClientId=Job.ClientId | ||
AND Job.JobId=File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId=File.PathId | ||
AND File.Name='%s' | ||
ORDER BY StartTime DESC FETCH FIRST 20 ROWS ONLY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
SELECT Job.JobId as JobId, CONCAT(Path.Path, Filename.Name) as Name, StartTime, Type as JobType, JobStatus, JobFiles, JobBytes | ||
FROM Client, Job, File, Filename, Path | ||
WHERE Client.Name = '%s' | ||
AND Client.ClientId = Job.ClientId | ||
AND Job.JobId = File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId = File.PathId | ||
AND Filename.FilenameId = File.FilenameId | ||
AND Filename.Name = '%s' | ||
ORDER BY StartTime DESC LIMIT 20 | ||
SELECT Job.JobId AS JobId, | ||
CONCAT(Path.Path,File.Name) AS Name, | ||
StartTime, | ||
TYPE AS JobType, | ||
JobStatus, | ||
JobFiles, | ||
JobBytes | ||
FROM Client, | ||
Job, | ||
FILE, | ||
Path | ||
WHERE Client.Name='%s' | ||
AND Client.ClientId=Job.ClientId | ||
AND Job.JobId=File.JobId | ||
AND File.FileIndex > 0 | ||
AND Path.PathId=File.PathId | ||
AND File.Name='%s' | ||
ORDER BY StartTime DESC | ||
LIMIT 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
# Query to get all files in a directory -- no recursing | ||
|
||
SELECT Job.JobId, File.FileIndex | ||
FROM Job, File, Path, Filename, Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId = File.JobId | ||
AND Path.Path = '%s' | ||
AND Client.Name = '%s' | ||
AND Job.ClientId = Client.ClientId | ||
AND Path.PathId = File.Pathid | ||
AND Filename.FilenameId = File.FilenameId | ||
GROUP BY File.FileIndex | ||
SELECT Job.JobId, | ||
File.FileIndex | ||
FROM Job, | ||
FILE, | ||
Path, | ||
Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId=File.JobId | ||
AND Path.Path='%s' | ||
AND Client.Name='%s' | ||
AND Job.ClientId=Client.ClientId | ||
AND Path.PathId=File.Pathid | ||
GROUP BY File.FileIndex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
SELECT Job.JobId, File.FileIndex | ||
FROM Job, File, Path, Filename, Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId = File.JobId | ||
AND Path.Path = '%s' | ||
AND Client.Name = '%s' | ||
AND Job.ClientId = Client.ClientId | ||
AND Path.PathId = File.Pathid | ||
AND Filename.FilenameId = File.FilenameId | ||
SELECT Job.JobId, | ||
File.FileIndex | ||
FROM Job, | ||
FILE, | ||
Path, | ||
Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId=File.JobId | ||
AND Path.Path='%s' | ||
AND Client.Name='%s' | ||
AND Job.ClientId=Client.ClientId | ||
AND Path.PathId=File.Pathid |
26 changes: 14 additions & 12 deletions
26
src/cats/dml/0044_uar_jobid_fileindex_from_dir.postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
# Query to get all files in a directory -- no recursing | ||
# Note, for PostgreSQL since it respects the "Single Value | ||
# rule", the results of the SELECT will be unoptimized. | ||
# Note, for PostgreSQL since it respects the Single Value | ||
# rule, the results of the SELECT will be unoptimized. | ||
# I.e. the same file will be restored multiple times, once | ||
# for each time it was backed up. | ||
|
||
SELECT Job.JobId, File.FileIndex | ||
FROM Job, File, Path, Filename, Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId = File.JobId | ||
AND Path.Path = '%s' | ||
AND Client.Name = '%s' | ||
AND Job.ClientId = Client.ClientId | ||
AND Path.PathId = File.Pathid | ||
AND Filename.FilenameId = File.FilenameId | ||
SELECT Job.JobId, | ||
File.FileIndex | ||
FROM Job, | ||
FILE, | ||
Path, | ||
Client | ||
WHERE Job.JobId IN (%s) | ||
AND Job.JobId=File.JobId | ||
AND Path.Path='%s' | ||
AND Client.Name='%s' | ||
AND Job.ClientId=Client.ClientId | ||
AND Path.PathId=File.Pathid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
# The Group By can return strange numbers when having multiple | ||
# version of a file in the same dataset. | ||
|
||
CREATE TABLE %s AS | ||
SELECT File.JobId, File.FileIndex, File.FileId | ||
FROM Job, File, ( | ||
SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId | ||
FROM btemp%s | ||
GROUP BY PathId, FilenameId | ||
) AS T1 | ||
JOIN Filename | ||
USING (FilenameId) | ||
WHERE T1.JobTDate = Job.JobTDate | ||
AND Job.JobId = File.JobId | ||
AND T1.PathId = File.PathId | ||
AND T1.FilenameId = File.FilenameId | ||
AND File.FileIndex > 0 | ||
AND Job.JobId IN ( | ||
SELECT DISTINCT JobId | ||
FROM btemp%s | ||
) | ||
SELECT File.JobId, | ||
File.FileIndex, | ||
File.FileId | ||
FROM Job, | ||
FILE, | ||
|
||
(SELECT MAX(JobTDate) AS JobTDate, | ||
PathId, | ||
Name | ||
FROM btemp%s | ||
GROUP BY PathId, | ||
Name) AS T1 | ||
WHERE T1.JobTDate = Job.JobTDate | ||
AND Job.JobId = File.JobId | ||
AND T1.PathId = File.PathId | ||
AND File.FileIndex > 0 | ||
AND Job.JobId IN | ||
(SELECT DISTINCT JobId | ||
FROM btemp%s) |
Oops, something went wrong.