From: Dagfinn Ilmari Mannsåker Date: Wed, 20 Apr 2016 16:23:46 +0000 (+0100) Subject: Use prepared statement from the start for populate on PostgreSQL X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22030f6f3e5ace15060ba1233682dfcfdfb318a7;p=dbsrgits%2FDBIx-Class-Historic.git Use prepared statement from the start for populate on PostgreSQL DBD::Pg since version 3.0.0 by default only starts using server-side prepared statements the second time ->execute is called on a given statement handle. Unless server-side prepared statements have been disabled (by setting the threshold to zero), make it use them immediately to avoid parsing the statement twice. --- diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 87a237d..88df494 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -157,6 +157,19 @@ EOS return $seq_expr; } +sub _dbh_execute_for_fetch { + #my ($self, $source, $sth, $tuple_status, @extra) = @_; + + # This is used for bulk insert, so make sure we use a server-side + # prepared statement from the start, unless it's disabled + local $_[2]->{pg_switch_prepared} = 1 if + modver_gt_or_eq( 'DBD::Pg', '3.0.0' ) + and + $_[2]->FETCH('pg_switch_prepared') > 0 + ; + + shift->next::method(@_); +} sub sqlt_type { return 'PostgreSQL';