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

Answer by user140142 for MySQL query taking too long

$
0
0

Normalize your database. The fact that one order is "self sustaining" and hence has a very simple insertion (you just let the web application copy data from the previous orders) has a negative effect on data extraction.Break your table in its basic components for example the table store would look like:

store_id int(11) NOT NULL,store_name varchar(64) NOT NULL,store_url varchar(255) NOT NULL

Also you are going to have a table customer, a table payment (one customer having multiple payments) and a table shipping (one customer has multiple shippings)

Order total has the same flaw. Have an order total table (without order_id), and either have the order_total_id on the order (if an order can only belong to one order total) or have a third table order2order_total which will emulate the many to many relation.

Simply by having the record shorter you gain significantly on performance.

Email is not the key of the customer (in the way the table is now designed, a customer may provide a fresh email on each order), so your group by criteria shall be "customer_id". Group By benefits of existing indexes, this will also speed up the query, especially if you apply the excellent hint of filtering early provided in the previous answer.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images

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