使用Postgres在DBIx :: Class中基于每个查询禁用准备好的语句

问题描述 投票:1回答:1

我有一些查询,这些查询在Postgres中使用准备好的语句时要慢得多(这是一个已知问题,请参见http://www.postgresql.org/docs/current/static/sql-prepare.html)。因此,我想关闭这些查询的语句准备。

在DBIx :: Class中,通过在connect_info中传递参数“ pg_server_prepare => 0”,可以在连接到数据库时全局关闭准备好的语句。但我看不到如何为现有连接更改此设置。给定一个DBIx :: Class :: Schema,我尝试过这个:

$schema->storage->connect_info->[0]->{'pg_server_prepare'} = 0;

如果在该调用之后记录了connect_info,则可以看到该参数的新值,但是数据库驱动程序仍使用准备好的语句。我也尝试断开并重新连接

$schema->storage->connect_info->[0]->{'pg_server_prepare'} = 0;
$schema->storage->disconnect;
$schema->connect(@{ $schema->storage->connect_info->[0] });

但是这也没有帮助。

任何想法?

postgresql perl dbix-class
1个回答
1
投票

我没有使用DBD :: Pg,所以我不能肯定地说,但这可能正在起作用:

$schema->storage->dbh_do(sub {
    my (undef, $dbh) = @_;
    local $dbh->{pg_server_prepare} = 0;
    # now do anything with $dbh you want
});
© www.soinside.com 2019 - 2024. All rights reserved.