title: Performance issue with ORDER BY + AND in sqlite
body: <p>I'm experiencing some weird behavior with SELECT statements in sqlite. There is one table with 3 Million records. E.g.</p>
  
  <pre><code>    SELECT * FROM table1 WHERE cond1;
  </code></pre>
  
  <p>reduces the output to 10000 records and finishes instantly. Same with</p>
  
  <pre><code>    SELECT * FROM table1 WHERE cond1 ORDER BY col1;
  </code></pre>
  
  <p>But</p>
  
  <pre><code>    SELECT * FROM table1 WHERE cond1 AND cond2 ORDER BY col1;
  </code></pre>
  
  <p>seems to take forever. The CPU is working for about 2 seconds and after that there is only I/O. CPU does nothing, memory is free.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Hope, it's not a newbie question and all i have to do is using an index (but why?).
  Thx for help!</p>
  
  <p>More concrete:
  the table structure:</p>
  
  <pre><code>    0|url|TEXT|0||1
      1|date|DATE|0||1
      2|md5sum|TEXT|0||0
      3|size|INTEGER|0||0
      4|archive|TEXT|0||0
      5|numScripts|INTEGER|0||0
      6|numScriptBytes|INTEGER|0||0
      7|numLinesBehaviour|INTEGER|0||0
      8|state|TEXT|0||0
  </code></pre>
  
  <p>the statement:</p>
  
  <pre><code>    SELECT * FROM t1 WHERE md5sum LIKE "00%" AND state=="okay" ORDER BY md5sum;
  </code></pre>
  
  <p>There is no connection between md5sum and state.</p>
  
  <p>I haven't created any indexes.</p>
  
  <p>What i also forgot to mention: The problem occurs only when the statement includes two or more string comparisons AND ordering. So </p>
  
  <pre><code>    SELECT * FROM t1 WHERE md5sum LIKE "00%" AND state=="okay";
  </code></pre>
  
  <p>works also fine.</p>
  
  <p>2 Update:
  An obvious workaround:</p>
  
  <pre><code>    CREATE TABLE temp (url TEXT, date DATE, ...
      INSERT INTO temp SELECT * FROM t1 WHERE state=="okay" AND md5sum LIKE "00%";
      SELECT * FROM temp ORDER BY md5sum;
  </code></pre>
  
  <p>But, damn, there must be an easier way.</p>