* We meant well but it turns out that the array unnest and join is actually very slow, as the join arguments do not get pushed down into the CTE (in Postgres 9/10 at least, later versions remove some of the optimization barriers in that specifc type of query) * This caused a seq scan on both device and device_port, and the query is executed many times during macsuck * The query is now rewritten to use ANY (macaddr[]) and without CTE, which seems to be around 20x faster
26 lines
595 B
Perl
26 lines
595 B
Perl
use utf8;
|
|
package App::Netdisco::DB::Result::Virtual::PortMacs;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use base 'DBIx::Class::Core';
|
|
|
|
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
|
|
|
__PACKAGE__->table("port_macs");
|
|
__PACKAGE__->result_source_instance->is_virtual(1);
|
|
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
|
SELECT ip, mac FROM device where mac = any (?::macaddr[])
|
|
UNION
|
|
SELECT ip, mac FROM device_port dp where mac = any (?::macaddr[])
|
|
ENDSQL
|
|
);
|
|
|
|
__PACKAGE__->add_columns(
|
|
'mac' => { data_type => 'macaddr' },
|
|
'ip' => { data_type => 'inet' },
|
|
);
|
|
|
|
1;
|