[Dbix-class] Problem using DBIx::Class::ResultClass::HashRefInflator

Andy Situ andy.situ at verizon.net
Mon Jan 12 16:55:10 GMT 2009


Jochen Luig wrote:
> use warnings;
>
> use Benchmark qw( cmpthese );
> use DBI;
> use lib '../MyApp/lib/';
> use MyAppDB;
>
>
> my $dbh = DBI->connect(...);
> my $schema = MyAppDB->connect(...);
>
> cmpthese( 50, { dbic => \&dbic, hashrefinflator =>
> \&dbic_HashRefInflator, plain_dbi => \&plain_dbi });
>
> sub dbic {
>     my @req = $schema->resultset('MyAppDB::Request')->search(
>         {message_id => \"IN (173, 174, 171, 1, 168, 144, 177, 111, 178,
> 172, 95, 196, 179)"},
>         {
>          columns=>[qw/ id message_id created status amount /] 
>         },	
>         );
> }
>
> sub dbic_HashRefInflator {
>     my $resultset = $schema->resultset('MyAppDB::Request');
>
> $resultset->result_class('DBIx::Class::ResultClass::HashRefInflator');
>     my @req = $resultset->search(
>         {message_id => \"IN (173, 174, 171, 1, 168, 144, 177, 111, 178,
> 172, 95, 196, 179)"},
>         {
>          columns=>[qw/ id message_id created status amount /] 
>         },	
>         );
> }
>
> sub plain_dbi {
>     my $query = $dbh->prepare('SELECT id, message_id, created, status,
> amount FROM requests WHERE message_id IN (173, 174, 171, 1, 168, 144,
> 177, 111, 178, 172, 95, 196, 179)');
>     my $result = $query->execute();
> }
>
>   
I could be mistaken but isn't this benchmark putting DBIC at an
unfair disadvantage? While DBIC cases are fetching all the results
the plain DBI version only executes the query.

--Andy



More information about the DBIx-Class mailing list