K
K
Khurshed Abdujalil2017-09-11 10:46:29
MySQL
Khurshed Abdujalil, 2017-09-11 10:46:29

What is the correct way to do PARTITION in MySQL?

There are tables of records with 6 million records, even simple selections are slow. Each entry has a city column (120 cities) should it be split into cities ? And in general, will partitioning help for optimization?

SELECT distinct(product.id), product.id,
               product.name,
               product.description,
               product.city_id,
               product.price,
               product.company_name,
               product.timestamp_update,
               product.company_id,
               city.name as city_name
FROM `product_to_tag` `v2t`
JOIN `product` ON product.id = v2t.product_id
JOIN `product_to_city` `vtc` ON product.id = vtc.product_id
JOIN `city` `c` ON c.id = vtc.city_id
LEFT JOIN `city` `city` ON city.id=product.city_id
LEFT JOIN `company` ON company.id=product.company_id
WHERE ((`product`.`publish` = 1)) AND (product.id !=  5016460) AND (c.id = 99 or c.parent_id = 99) AND ((`v2t`.`tag_id` IN (65, 181, 228, 1135)))
ORDER BY `product`.`timestamp_update` DESC LIMIT 30;

table product
KAgWWPOC4DaYxA.jpg
indices
YmENN96F0Yxvk2.jpg
product_to_tag
279c75cd4a.jpg
product_to_city
J2b33DKuXbWlNA
company
krDxxj5hEqXwNr.jpg
city
f11a6da2b0.jpg
explain
8AnBBp7fj4kxEA.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-09-11
@BorisKorobkov

6M is not enough. It is necessary not to partition the table, but to write the query correctly and, possibly, build indexes.
https://dev.mysql.com/doc/refman/5.7/en/explain.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question