title: PHP SQLite PDO very slow when using "GROUP BY" clause
body: <p>I Have this project here playing with Philly crime data.  I'm building this query to select incidents by type and police district.  It takes 21 seconds in PHP and Zend, but under 3 seconds on the command line.</p>
  
  <p>I debug with Zend_Db_Profiler with debug output like so:</p>
  
  <blockquote>
    <p>numQueries: 2<br/>
    query: connect<br/>
    elapsed seconds: 0.0019519329071045<br/>
    query: SELECT "incident".* FROM "incident" WHERE (dc_dist = '15') AND
    (lower(text_general_code) = 'homicide') GROUP BY "location_block"<br/>
    elapsed seconds: 21.583115816116<br/></p>
  </blockquote>
  
  <p>If I copy and paste that very same select statement into the sqlite3 command line client, it takes maybe 3 seconds.</p>
  
  <p>Am I missing something here?  Why is Zend taking 21 seconds?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>running just a script using PDO still results in a 21 second query:</p>
  
  <pre><code>// Create (connect to) SQLite database in file
      $file_db = new PDO('sqlite:../db/crime.db');
      // Set errormode to exceptions
      $file_db-&gt;setAttribute(PDO::ATTR_ERRMODE, 
                              PDO::ERRMODE_EXCEPTION);
  
      $start_time = microtime(true);
      // Select all data from memory db messages table 
      $result = $file_db-&gt;query("SELECT 'incident'.* FROM 'incident' WHERE (dc_dist = '15') AND (lower(text_general_code) = 'homicide') GROUP BY 'location_block'");
      $end_time = microtime(true);
  
      $elapsed_time = $end_time - $start_time;
  
      print "query took " . $elapsed_time . " seconds\n";
  </code></pre>
  
  <p>output:</p>
  
  <blockquote>
    <p>query took 21.751929998398 seconds</p>
  </blockquote>
  
  <p><strong>2nd Update</strong></p>
  
  <p>It looks like it's the group by addition to the sql statement that's holding it all up.  If I remove it, and run the pdo script or the zend framework application, it reaches the same speeds as directly from the command line:</p>
  
  <p>With 'GROUP BY' clause, 23 seconds:</p>
  
  <blockquote>
    <p>numQueries: 2<br/>
    query: connect<br/>
    elapsed seconds: 0.0007779598236084<br/>
    query: SELECT "incident".* FROM "incident" WHERE (dc_dist = '15') AND  (lower(text_general_code) = 'homicide') GROUP BY "location_block"<br/>
    elapsed seconds: 23.092380046844<br/></p>
  </blockquote>
  
  <p>Without 'GROUP BY' clause, under a second:</p>
  
  <blockquote>
    <p>numQueries: 2
    query: connect<br/>
    elapsed seconds: 0.0011060237884521<br/>
    query: SELECT "incident".* FROM "incident" WHERE (dc_dist = '15') AND  (lower(text_general_code) = 'homicide')<br/>
    elapsed seconds: 0.080777883529663<br/></p>
  </blockquote>