Quantcast
Channel: MySQL query taking too long - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Rick James for MySQL query taking too long

$
0
0

To do the filtering sooner, change the subquery to

( SELECT email,         COUNT(*) AS email_ct      FROM oc_order      GROUP BY  email      HAVING COUNT(*) > 3 ) AS xxx

Then remove xxx.`Orders Count` >3 as being redundant.

To make the subquery run faster, oc_orders needs INDEX(email)

In oc_order_total, change KEY order_id (order_id) to KEY order_id (order_id, code)

With email_ct, you can add this to the main part of the query:

email_ct as 'Orders Count',

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>