gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:36:55 25 4
gpt4 key购买 nike

我有一些查询在 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] });

但这也没有帮助。

有什么想法吗?

最佳答案

我没有使用 DBD::Pg,所以我不能肯定地说,但这 - 可能 - 有效:

$schema->storage->dbh_do(sub {
my (undef, $dbh) = @_;
local $dbh->{pg_server_prepare} = 0;
# now do anything with $dbh you want
});

关于postgresql - 在 DBIx::Class with Postgres 中基于每个查询禁用准备好的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7804374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com