Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat index(es) needs to be added for this query to work properly?
    primarykey
    data
    text
    <p>This query pops up in my slow query logs:</p> <pre><code>SELECT COUNT(*) AS ordersCount, SUM(ItemsPrice + COALESCE(extrasPrice, 0.0)) AS totalValue, SUM(ItemsPrice) AS totalValue, SUM(std_delivery_charge) AS totalStdDeliveryCharge, SUM(extra_delivery_charge) AS totalExtraDeliveryCharge, this_.type AS y5_, this_.transmissionMethod AS y6_, this_.extra_delivery AS y7_ FROM orders this_ WHERE this_.deliveryDate BETWEEN '2010-01-01 00:00:00' AND '2010-09-01 00:00:00' AND this_.status IN(1, 3, 2, 10, 4, 5, 11) AND this_.senderShop_id = 10017 GROUP BY this_.type, this_.transmissionMethod, this_.extra_delivery ORDER BY this_.deliveryDate DESC; </code></pre> <p>The table is InnoDB and has about 880k rows and takes between 9-12 seconds to execute. I tried adding the following index <code>ALTER TABLE orders ADD INDEX _deliverydate_senderShopId_status ( deliveryDate , senderShop_id , status, type, transmissionMethod, extra_delivery);</code> with no practical gains. Any help and/or suggestion is welcomed</p> <p>Here is the query execution plan right now:</p> <pre> id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE this_ ref FKC3DF62E57562BA6F 8 const 139894 100.00 Using where; Using temporary; Using filesort </pre> <p>I took out the possible_keys value out of the text because i think it listed all the indexes in the table. The key used (FKC3DF62E57562BA6F) looks like </p> <pre> Keyname Type Unique Packed Field Cardinality Collation Null Comment FKC3DF62E57562BA6F BTREE No No senderShop_id 4671 A </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload