title: MySql why take to long to sorting results include SELECT IF() as Alice
body: <p>I have two tables products and products_actions</p>
  <p>in products i store ordinary data like id,name,manufacure,price,date_added</p>
  <p>in product_actions i store data like: id, product_id, store_id, operator, status_id</p>
  <p>then problem is when i display data in DataTables and try to sort out by store_id is take to long time like 3-4 seconds (if i sort by name or id is taking less then half second)
  even i index product_id in product_actions still issue with only 2k records in products_actions and 14k records in products</p>
  <p>How to fix the problem with sorting when i use IF as Alice , look like no indexing there</p>
  <pre><code>    SELECT p.id, p.name, p.mpn, p.price, p.comment, p.status, p.date_added, m.name AS manufacture,
  (SELECT IF(pa.store_id = 9, pa.status, 'null') FROM products_actions pa WHERE p.id = pa.product_id AND pa.store_id = 9) AS store_1,
  (SELECT IF(pa.store_id = 4, pa.status, 'null') FROM products_actions pa WHERE p.id = pa.product_id AND pa.store_id = 4) AS store_2,
  (SELECT IF(pa.store_id = 5, pa.status, 'null') FROM products_actions pa WHERE p.id = pa.product_id AND pa.store_id = 5) AS store_3
  FROM products p
  LEFT JOIN manufacture m ON p.manufacture = m.id
  </code></pre>