title: Mysql subquery slow
body: <p>I have two tables that track sales:</p>
  <pre><code>orders                 order_line_items
  ------                 ----------------
  id                     id
  customer_id            order_id
  created_datetime       item_id
                         quantity
                         was_paid_for
  </code></pre>
  <p>An <code>order</code> can have many <code>order_line_items</code>.  For some orders, all of the line items have been paid for.  For other orders, they have not all been paid for.</p>
  <p>I am trying to fetch a list of all the orders for a specific customer, and indicate if the order was fully paid for, or not.  I have it working with this query:</p>
  <pre><code>SELECT o.id,
         (SELECT count(*) from order_line_items WHERE order_id = o.id AND was_paid_for = 0) = 0 as isFullyPaid
  FROM orders o
  WHERE o.customer_id = 12345
  </code></pre>
  <p>However some customers have 1000+ orders and the query takes 70 seconds to run (this is a simplified example, the real one joins in five other tables).</p>
  <p>Is indexes the only way to speed this up?  Thanks.</p>