[Dbix-class] RFC: DBIx::Class::OverrideDbhAttributes::PerResultSet

BUCHMULLER Norbert norbi.lists at nix.hu
Wed Jun 1 18:36:19 GMT 2011


Hi All,

could you comment on this new module? Does it make sense at all?

https://github.com/mendel/DBIx-Class-OverrideDbhAttributes-PerResultSet/blob/master/lib/DBIx/Class/Storage/DBI/OverrideDbhAttributes/PerResultSet.pm

Background info: we use PostgreSQL and we have some queries where we have
to let the query planner know the actual (bind) values involved in the
query in order to make it choose a better query plan (eg. using a
partial index); but for the rest of the queries we benefit from the
server-side prepared statements (with bind values).

One approach is to inline the "bind values" as literal SQL in the
conditions (works but ugly), alternatively with DBD::Pg you can disable
server-side prepared statements on a per $sth basis, you just need a way
to toggle it through some DBIC API. So i wrote this module that lets you
do this: override $dbh attributes on a per-resultset basis.

An example:

# this disables server-side prepared statements for DBD::Pg - only
# for the SELECTs generated by this resultset
my $djs_rs = $schema->resultset('Artist')->search(
    {
        name => { -like => 'DJ. %' },
    },
    {
        dbh_attributes => { pg_server_prepare => 0 },
    }
);

# now it can benefit from a b-tree index on "name" (the planner
# sees that the pattern starts with literal chars)
my $num_djs = $artist_rs->count;

norbi



More information about the DBIx-Class mailing list