--- 
author: 
  email: rafl@fsfe.org
  keyid: 742f2a428e635a5e
  name: Florian Ragwitz
categories: 
  - Perl
date: 2006-06-11T11:36:58Z
guid: cfe661e2-1ca1-453f-9b97-2f9e96debc26
modified: 2007-10-17T22:37:48Z
raw: "=pod\n\nL<David|http://www.davidpashley.com/cgi/pyblosxom.cgi/>, you\nL<wrote|http://www.davidpashley.com/cgi/pyblosxom.cgi/2006/06/11#class-dbi-performance>\nabout L<Class::DBI|http://wiki.class-dbi.com/wiki/Main_Page> performance.\n\nEven without benchmarking you could have\nL<found out|http://rose.sourceforge.net/wiki/index.php/RDBO/Benchmark>,\nthat Class::DBI is quite slow. Fortunately there are some alternative\nobject-relational mappers available in the perl universe. The best ones I found\nso far are\nL<Rose::DB::Object|http://search.cpan.org/~jsiracusa/Rose-DB-Object/> and\nL<DBIx::Class|http://search.cpan.org/~jrobinson/DBIx-Class/>. I took a closer\nlook at both and would like to share my experience.\n\n\nAs L<this|http://rose.sourceforge.net/wiki/index.php/RDBO/Benchmark> shows,\nRDBO is faster than DBIC in most of the case. The generated SQL doesn't differ\ntoo much and therefor it must be the perl side of things that makes the\ndifference.\n\nMatt S Trout <dbix-class@trout.me.uk> says:\n\n  However, RDBO achieves its perl speed by aggressive inlining of\n  stuff etc. - for example the main object retrieval function in\n  RDBO's manager class is >3000 lines in a single sub. DBIC values\n  extensibility over a few extra sub calls, so methods are much more\n  broken out and there are many more ways to hook into the DBIC\n  execution process to extend.\n\n\nAlso its idea of resultsets is something I really love. Here's a small example to illustrate that:\n\n  lang:Perl\n  my $user_rs = $schema->resultset('User')->search({ registered => 1 });\n  $user_rs    = $user_rs->search(\n\t\t  { comment.title => 'Foo' },\n\t\t  {\n\t\t  \tjoin     => { 'article' => 'comment' },\n\t\t\torder_by => 'user.name',\n\t\t  },\n  );\n\n  # no sql executed yet.\n  # now you can use your resultset as an iterator or query a list\n  # of User objects from it or ..\n\n  while (my $user = $user_rs->next) {\n\t  ...\n  }\n\n  # or\n\n  my $count = $user_rs->count;\n\n\nUsing these resultset makes it extremely easy to built up queries piece by\npiece and to work together well with, for example, a templating system. You\ndon't need to fetch all row-objects and give them to your template. You can\njust pass the iterator to the template library.\n\n\nThere's a lot more to say about this two object-relational mappers (for example\nRDBO supports prefetching of multiple one-to-many at once, which DBIC doesn't),\nbut maybe you just should take a look yourself. I personally prefer DBIx::Class\nfor its vast extensibility.\n\n=cut\n"
signed: 1
summary: " David, you wrote about Class::DBI performance. Even without benchmarking …"
tags: []

text: "    David, you wrote about Class::DBI performance.\n\n    Even without benchmarking you could have found out, that Class::DBI\n    is quite slow. Fortunately there are some alternative object-rela-\n    tional mappers available in the perl universe. The best ones I found\n    so far are Rose::DB::Object and DBIx::Class. I took a closer look at\n    both and would like to share my experience.\n\n    As this shows, RDBO is faster than DBIC in most of the case. The\n    generated SQL doesn't differ too much and therefor it must be the\n    perl side of things that makes the difference.\n\n    Matt S Trout <dbix-class@trout.me.uk> says:\n\n      However, RDBO achieves its perl speed by aggressive inlining of\n      stuff etc. - for example the main object retrieval function in\n      RDBO's manager class is >3000 lines in a single sub. DBIC values\n      extensibility over a few extra sub calls, so methods are much more\n      broken out and there are many more ways to hook into the DBIC exe-\n      cution process to extend.\n\n    Also its idea of resultsets is something I really love. Here's a s-\n    mall example to illustrate that:\n\n      lang:Perl my $user_rs = $schema->resultset('User')->search({ reg-\n      istered => 1 }); $user_rs = $user_rs->search( { comment.title =>\n      'Foo' }, { join => { 'article' => 'comment' }, order_by => 'user.-\n      name', }, );\n\n      # no sql executed yet. now you can use your resultset as an itera-\n      # tor or query a list of User objects from it or ..\n\n      while (my $user = $user_rs->next) { ... }\n\n      # or\n\n      my $count = $user_rs->count;\n\n    Using these resultset makes it extremely easy to built up queries\n    piece by piece and to work together well with, for example, a tem-\n    plating system. You don't need to fetch all row-objects and give\n    them to your template. You can just pass the iterator to the tem-\n    plate library.\n\n    There's a lot more to say about this two object-relational mappers\n    (for example RDBO supports prefetching of multiple one-to-many at\n    once, which DBIC doesn't), but maybe you just should take a look y-\n    ourself. I personally prefer DBIx::Class for its vast extensibility.\n"
title: Class::DBI is dead
type: pod
uri: http://perldition.org/articles/Class%3A%3ADBI%20is%20dead.pod
xhtml: "<div class=\"pod\">\n<p><a href=\"http://www.davidpashley.com/cgi/pyblosxom.cgi/\">David</a>, you\n<a href=\"http://www.davidpashley.com/cgi/pyblosxom.cgi/2006/06/11#class-dbi-performance\">wrote</a>\nabout <a href=\"http://wiki.class-dbi.com/wiki/Main_Page\">Class::DBI</a> performance.</p>\n<p>Even without benchmarking you could have\n<a href=\"http://rose.sourceforge.net/wiki/index.php/RDBO/Benchmark\">found out</a>,\nthat Class::DBI is quite slow. Fortunately there are some alternative\nobject-relational mappers available in the perl universe. The best ones I found\nso far are\n<a href=\"http://search.cpan.org/~jsiracusa/Rose-DB-Object/\">Rose::DB::Object</a> and\n<a href=\"http://search.cpan.org/~jrobinson/DBIx-Class/\">DBIx::Class</a>. I took a closer\nlook at both and would like to share my experience.</p>\n\n\n\n<p>As <a href=\"http://rose.sourceforge.net/wiki/index.php/RDBO/Benchmark\">this</a> shows,\nRDBO is faster than DBIC in most of the case. The generated SQL doesn't differ\ntoo much and therefor it must be the perl side of things that makes the\ndifference.</p>\n<p>Matt S Trout &lt;dbix-class@trout.me.uk&gt; says:</p>\n<pre>However, RDBO achieves its perl speed by aggressive inlining of\nstuff etc. - for example the main object retrieval function in\nRDBO's manager class is &gt;3000 lines in a single sub. DBIC values\nextensibility over a few extra sub calls, so methods are much more\nbroken out and there are many more ways to hook into the DBIC\nexecution process to extend.\n\n\n</pre>\n<p>Also its idea of resultsets is something I really love. Here's a small example to illustrate that:</p>\n<pre><span class=\"Keyword\">my</span><span class=\"Normal\"> </span><span class=\"DataType\">$user_rs</span><span class=\"Normal\"> = </span><span class=\"DataType\">$schema</span><span class=\"Normal\">-&gt;</span><span class=\"DataType\">resultset</span><span class=\"Normal\">(</span><span class=\"Operator\">&apos;</span><span class=\"String\">User</span><span class=\"Operator\">&apos;</span><span class=\"Normal\">)</span><span class=\"Operator\">-</span><span class=\"Normal\">&gt;search({ registered =&gt; </span><span class=\"Float\">1</span><span class=\"Normal\"> });</span><span class=\"Normal\">\n</span><span class=\"DataType\">$user_rs</span><span class=\"Normal\">    = </span><span class=\"DataType\">$user_rs</span><span class=\"Normal\">-&gt;</span><span class=\"DataType\">search</span><span class=\"Normal\">(</span><span class=\"Normal\">\n</span><span class=\"Normal\">  { comment.title =&gt; </span><span class=\"Operator\">&apos;</span><span class=\"String\">Foo</span><span class=\"Operator\">&apos;</span><span class=\"Normal\"> },</span><span class=\"Normal\">\n</span><span class=\"Normal\">  {</span><span class=\"Normal\">\n</span><span class=\"Normal\">  \t</span><span class=\"Function\">join</span><span class=\"Normal\">     =&gt; { </span><span class=\"Operator\">&apos;</span><span class=\"String\">article</span><span class=\"Operator\">&apos;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&apos;</span><span class=\"String\">comment</span><span class=\"Operator\">&apos;</span><span class=\"Normal\"> },</span><span class=\"Normal\">\n</span><span class=\"Normal\">\torder_by =&gt; </span><span class=\"Operator\">&apos;</span><span class=\"String\">user.name</span><span class=\"Operator\">&apos;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">  },</span><span class=\"Normal\">\n</span><span class=\"Normal\">);</span>\n\n<span class=\"Comment\"># no sql executed yet.</span><span class=\"Comment\">\n</span><span class=\"Comment\"># now you can use your resultset as an iterator or query a list</span><span class=\"Comment\">\n</span><span class=\"Comment\"># of User objects from it or ..</span>\n\n<span class=\"Keyword\">while</span><span class=\"Normal\"> (</span><span class=\"Keyword\">my</span><span class=\"Normal\"> </span><span class=\"DataType\">$user</span><span class=\"Normal\"> = </span><span class=\"DataType\">$user_rs</span><span class=\"Normal\">-&gt;</span><span class=\"DataType\">next</span><span class=\"Normal\">) {</span><span class=\"Normal\">\n</span><span class=\"Normal\"> ...</span><span class=\"Normal\">\n</span><span class=\"Normal\">}</span>\n\n<span class=\"Comment\"># or</span>\n\n<span class=\"Keyword\">my</span><span class=\"Normal\"> </span><span class=\"DataType\">$count</span><span class=\"Normal\"> = </span><span class=\"DataType\">$user_rs</span><span class=\"Normal\">-&gt;</span><span class=\"DataType\">count</span><span class=\"Normal\">;</span>\n\n\n</pre>\n<p>Using these resultset makes it extremely easy to built up queries piece by\npiece and to work together well with, for example, a templating system. You\ndon't need to fetch all row-objects and give them to your template. You can\njust pass the iterator to the template library.</p>\n\n\n\n<p>There's a lot more to say about this two object-relational mappers (for example\nRDBO supports prefetching of multiple one-to-many at once, which DBIC doesn't),\nbut maybe you just should take a look yourself. I personally prefer DBIx::Class\nfor its vast extensibility.</p>\n\n\n</div>"
