2014-06-05 3 views
0

J'ai une "requête lente" et n'a pas trouvé le "bon" index pour éviter la requête lente.requête lente mysql n'a pas trouvé le bon index

La requête est:

SELECT c.uid FROM tx_gwcalendar_competition c,tx_gestionprofildb_discipline d WHERE c.hidden=0 and c.deleted=0 and c.discipline=d.uid and d.usergroup=19 LIMIT 1; 

et mes tables sont:

CREATE TABLE IF NOT EXISTS `tx_gwcalendar_competition` (
    `uid` int(11) NOT NULL AUTO_INCREMENT, 
    `pid` int(11) NOT NULL DEFAULT '0', 
    `tstamp` int(11) NOT NULL DEFAULT '0', 
    `crdate` int(11) NOT NULL DEFAULT '0', 
    `cruser_id` int(11) NOT NULL DEFAULT '0', 
    `sys_language_uid` int(11) NOT NULL DEFAULT '0', 
    `l10n_parent` int(11) NOT NULL DEFAULT '0', 
    `l10n_diffsource` mediumtext, 
    `deleted` tinyint(4) NOT NULL DEFAULT '0', 
    `hidden` tinyint(4) NOT NULL DEFAULT '0', 
    `title` tinytext, 
    `discipline` int(11) NOT NULL DEFAULT '0', 
    `dept` tinytext, 
    `ville` tinytext, 
    `distance` tinytext, 
    `date` int(11) NOT NULL DEFAULT '0', 
    `description` text, 
    PRIMARY KEY (`uid`), 
    KEY `parent` (`pid`), 
    KEY `deleted` (`deleted`,`hidden`) 
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8659 ; 

et

CREATE TABLE IF NOT EXISTS `tx_gestionprofildb_discipline` (
    `uid` int(11) NOT NULL AUTO_INCREMENT, 
    `pid` int(11) NOT NULL DEFAULT '0', 
    `tstamp` int(11) NOT NULL DEFAULT '0', 
    `crdate` int(11) NOT NULL DEFAULT '0', 
    `cruser_id` int(11) NOT NULL DEFAULT '0', 
    `deleted` tinyint(4) NOT NULL DEFAULT '0', 
    `hidden` tinyint(4) NOT NULL DEFAULT '0', 
    `libelle` tinytext, 
    `description` text, 
    `usergroup` int(11) NOT NULL DEFAULT '0', 
    `sportup_tag` tinytext, 
    `form_mutation` text, 
    `documents` text, 
    `mutation` tinyint(3) NOT NULL DEFAULT '0', 
    `nolicence` tinyint(3) NOT NULL DEFAULT '0', 
    `agendahtml` text, 
    `objectifhtml` text, 
    `havestat` tinyint(3) NOT NULL DEFAULT '0', 
    `description_conseil` text, 
    `frais_admin` tinytext, 
    PRIMARY KEY (`uid`), 
    KEY `parent` (`pid`), 
    KEY `deleted_hidden_libelle` (`deleted`,`hidden`,`libelle`(20)) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=53 ; 

Quand je lance une expliquer que je suis arrivé que:

id select_type table type possible_keys key key_len ref rows Extra 
1 SIMPLE c ALL deleted NULL NULL NULL 8658 Using where 
1 SIMPLE d eq_ref PRIMARY PRIMARY 4 tbs888dbnew.c.discipline 1 Using where 

J'essaie de mettre un index sur delete/hidden, mais maintenant je change encore avec 8658 key_len pour la première ligne, comme si je n'ai pas mis d'index ... mes connaissances dans mysql sont limitées, donc je n'ai pas savoir quoi faire (et si c'est possible ...). Donc, si quelqu'un a un conseil, n'hésitez pas.

Merci beaucoup

Répondre

0

Essayez de changer l'ordre de deleted et hidden dans votre définition d'index deleted_hidden_libelle, ou modifier l'ordre dans lequel ils apparaissent dans la clause where de votre requête.

Ils doivent apparaître dans l'index dans le même ordre qu'ils apparaissent dans la clause where.

En outre, vous devez ajouter un index pour le champ que vous utilisez pour joindre les tables:

KEY `discipline` (`discipline`) 
+0

J'essaie juste, mais rien changer ... stil le même résultat. Merci – Mitchum

+0

@Mitchum Voir mon édition – Eran

+0

Salut, j'essaie d'ajouter la clé de la discipline, mais rien ne change ... Je suis perdu. Merci – Mitchum