From a5b62504a90003af5b043136dc650c7ea629ef9b Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sun, 6 Apr 2025 18:59:27 +0200 Subject: [PATCH] pbackup: Use SQL to find jobs for FULL 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. --- bin/pbackup | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/pbackup b/bin/pbackup index ad3c881..2069e6f 100755 --- a/bin/pbackup +++ b/bin/pbackup @@ -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;