Skip to content

Commit

Permalink
pbackup: Use SQL to find jobs for FULL
Browse files Browse the repository at this point in the history
FULL backups want only jobs without existing stat records. Usually,
there will be none. Select jobs without stat records by `LEFT JOIN
stat ON stat_job_id = job_id WHERE stat_job_id IS NULL`.

This reduced the time for test runs to discover that there are no FULL
jobs to do in an actual database from 2.02 seconds to 0.06 seconds.
  • Loading branch information
donald committed Apr 7, 2025
1 parent 81351fa commit a5b6250
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions bin/pbackup
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,30 @@ sub do_a_job {

$dbh->begin_work();

my $sth = $dbh->prepare('
SELECT job_id,job_name,job_ok,job_started,path_server,path_path,
CASE WHEN job_ok THEN job_started-? ELSE JOB_STARTED-? END as due
FROM job,path
WHERE job_path_id=path_id
my $sth;
if ($type eq 'F') {
$sth = $dbh->prepare('
SELECT job_id, job_name, job_ok, job_started, path_server, path_path,
CASE WHEN job_ok THEN job_started - ? ELSE JOB_STARTED - ? END as due
FROM job
LEFT JOIN stat ON stat_job_id = job_id
INNER JOIN path ON path_id = job_path_id
WHERE stat_job_id IS NULL
AND job_enabled
AND due<=0
AND due <= 0
ORDER BY due
');
} else {
$sth = $dbh->prepare('
SELECT job_id, job_name, job_ok, job_started, path_server, path_path,
CASE WHEN job_ok THEN job_started - ? ELSE JOB_STARTED - ? END as due
FROM job
INNER JOIN path ON job_path_id = path_id
WHERE job_enabled
AND due <= 0
ORDER BY due
');
}
$sth->execute(time-24*60*60, time-8*60*60);
my ($job_id, $job_name, $job_ok, $job_started, $path_server, $path_path, $due);
my $datadir;
Expand Down

0 comments on commit a5b6250

Please sign in to comment.