【问题标题】:Disable prepared statements on a per-query basis in DBIx::Class with Postgres在使用 Postgres 的 DBIx::Class 中基于每个查询禁用准备好的语句
【发布时间】:2011-10-18 08:26:27
【问题描述】:

在 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】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 2012-04-09
      相关资源
      最近更新 更多