title: Extremely slow sql query when using multiple inner join and order clauses
body: <p>I have a MySQL database with three relevant tables, <strong>t1</strong> with <strong>6598</strong> rows, <strong>t2</strong> with <strong>1713</strong> rows and <strong>t3</strong> with <strong>10023</strong> rows.</p>
  
  <p>Details:</p>
  
  <pre class="lang-sql prettyprint-override"><code>TABLE t1 (
      `id` SERIAL,
      `t2_id` BIGINT UNSIGNED NOT NULL,
      `t3_id` BIGINT UNSIGNED,
      PRIMARY KEY (`id`),
      FOREIGN KEY (t2_id) REFERENCES t2(id),
      FOREIGN KEY (t3_id) REFERENCES t3(id)   
  );
  
  TABLE t2(
      `id` SERIAL,
      `name` VARCHAR(128) NOT NULL,
      PRIMARY KEY (`id`)
  );
  
  TABLE t3 (
      `id` SERIAL,
      `name` VARCHAR(128),
      PRIMARY KEY (`id`)
  );
  </code></pre>
  
  <p>I want perform the following query but it does not finish (takes forever basically):</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT *
  FROM t1
  INNER JOIN t3
  ON t1.t3_id = t3.id
  INNER JOIN t2
  ON t1.t2_id = t2.id
  WHERE (t3.name NOT NULL)
  ORDER BY t3.name ASC , t1.id ASC
  LIMIT 25
  </code></pre>
  
  <p>When i remove the order clause it works very fast (0.17 sec).</p>
  
  <p>How could i change the query to make it work?</p>