Answer the question
In order to leave comments, you need to log in
How to speed up GROUP BY execution?
Hello!
There are 700 tables on 5 records, each table weighs on 200 Mb.
The table structure is as follows:
CREATE TABLE `table` (
`id` int(11),
`id2` int(11),
`id3` int(11),
`p1` int(11),
`p2` int(11),
KEY `id` (`id`)
) ENGINE=MyISAM;
SELECT `id1`, `id2`, `id3`, `p1`, COUNT(`p1`) AS `count`, `p2`
FROM `table`
GROUP BY `id1`, `id3`, `p1`, `p2`
Answer the question
In order to leave comments, you need to log in
Such a query cannot be applied to the table, you have fields in the select that do not participate in the grouping and without the use of aggregate functions.
Show explain query and show create tables.
Judging by the runtime, the indexes are missing or incorrectly placed. Tables without sharding?
ZY If you do not want to publicly shine with data, then you can personally, but already in the context of paid work.
Does the data structure really not allow all these 700 tables to be reduced into one, adding several fields, if necessary, with additional. criteria? It's just awful, to design a database like that. Yes, and suddenly you need to update the data structure (read "tables") and then you need to add / delete a column in each of the 700 tables?
Try running mysqltuner.pl and see its recommendations for tuning mysql. Have you tried the index on all fields (`id1`, `id3`, `p1`, `p2`)?
Could you explain in words what the request should do? The query you wrote doesn't make sense.
If you need to get the number of unique combinations (id1, id2, id3, p2), then try this query:
SELECT `id1`, `id2`, `id3`, COUNT(*) AS `count`, `p2`
FROM `table`
GROUP BY `id1`, `id2`, `id3`, `p2`
ORDER BY NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question