Limit instances to deduplicate by id

The instances table is partitioned by id. If we restrinct the search to
recent ids we only have to search a few partitions which should be
faster.
This commit is contained in:
Peter J. Holzer 2023-11-29 06:04:02 +01:00
parent 118bb0a2e7
commit 45095845fd
1 changed files with 6 additions and 1 deletions

View File

@ -727,6 +727,9 @@ sub linkdup {
push @{ $self->{sessions_on_same_device} }, $r->{id}; # We only use the id push @{ $self->{sessions_on_same_device} }, $r->{id}; # We only use the id
} }
my $self->{min_instance_id} = $self->{dbh}->selectrow_array("select min(id) from instances where session in " . join(", ", map("?", @{ $self->{sessions_on_same_device} })) . ")");
$self->log(3, "min_instance_id set to $self->{min_instance_id}");
} }
my $tdb0 = gettimeofday(); my $tdb0 = gettimeofday();
my $tdb1; my $tdb1;
@ -735,8 +738,9 @@ sub linkdup {
and file_owner=? and file_group=? and file_acl=? and file_owner=? and file_group=? and file_acl=?
and file_unix_bits=? and file_unix_bits=?
and checksum=? and online=1 and checksum=? and online=1
and instances.file=files.id
and versions2.id=instances.version and versions2.id=instances.version
and instances.id >= ?
and instances.file=files.id
and instances.session=sessions.id and instances.session=sessions.id
and sessions.id in (" . join(", ", map("?", @{ $self->{sessions_on_same_device} })) . ")" . and sessions.id in (" . join(", ", map("?", @{ $self->{sessions_on_same_device} })) . ")" .
" order by instances.session desc " order by instances.session desc
@ -746,6 +750,7 @@ sub linkdup {
$f->{o}, $f->{g}, $f->{acl}, $f->{o}, $f->{g}, $f->{acl},
join(',', map {$f->{$_} ? ($_) : ()} qw(setuid setgid sticky)), join(',', map {$f->{$_} ? ($_) : ()} qw(setuid setgid sticky)),
$f->{checksum}, $f->{checksum},
$self->{min_instance_id},
@{ $self->{sessions_on_same_device} }, @{ $self->{sessions_on_same_device} },
); );
my $st = stat($backup_filename); my $st = stat($backup_filename);