Je suis en cours d'exécution de la requête suivante sur un Macbook Pro 2,53 avec 4 Go de RAM:Optimisation de la requête MySQL, prend presque 20 secondes!
SELECT
c.id AS id,
c.name AS name,
c.parent_id AS parent_id,
s.domain AS domain_name,
s.domain_id AS domain_id,
NULL AS stats
FROM
stats s
LEFT JOIN stats_id_category sic ON s.id = sic.stats_id
LEFT JOIN categories c ON c.id = sic.category_id
GROUP BY
c.name
Il faut environ 17 secondes pour terminer.
EXPLIQUEZ:
alt text http://img7.imageshack.us/img7/1364/picture1va.png
Les tables:
Information:
Number of rows: 147397
Data size: 20.3MB
Index size: 1.4MB
Tableau:
CREATE TABLE `stats` (
`id` int(11) unsigned NOT NULL auto_increment,
`time` int(11) NOT NULL,
`domain` varchar(40) NOT NULL,
`ip` varchar(20) NOT NULL,
`user_agent` varchar(255) NOT NULL,
`domain_id` int(11) NOT NULL,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP,
`referrer` varchar(400) default NULL,
KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=147398 DEFAULT CHARSET=utf8
Informations seco Table e:
Number of rows: 1285093
Data size: 11MB
Index size: 17.5MB
Deuxième tableau:
CREATE TABLE `stats_id_category` (
`stats_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
KEY `stats_id` (`stats_id`,`category_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Informations troisième table:
Number of rows: 161
Data size: 3.9KB
Index size: 8KB
Troisième table:
CREATE TABLE `categories` (
`id` int(11) NOT NULL auto_increment,
`parent_id` int(11) default NULL,
`name` varchar(40) NOT NULL,
`questions_category_id` int(11) NOT NULL default '0',
`rank` int(2) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=205 DEFAULT CHARSET=latin1
Espérons que quelqu'un peut me aider à accélérer cela.
Quelles sont les spécifications de votre serveur? 17 sec peut ne pas être trop mauvais pour joindre 100K rangées avec des rangées de 1M. – dave
Veuillez inclure la sortie d'EXPLAIN. – derobert
vous pouvez utiliser limite et traiter votre sortie par lots. Quel genre de traitement faites-vous avec tellement d'enregistrements? –