2010-11-08 4 views
1

J'ai une requête qui selon ma requête lente LOGGUE est un peu lent ....Impossible de dupliquer journal de requêtes lentes rows_examined

Query_time: 8.408943 Lock_time: 0.000119 Rows_sent: 1 Rows_examined: 2911766 

MAIS, quand je lance la requête avec EXPLAIN devant elle, Je ne reçois pas les mêmes résultats ...

id select_type table type possible_keys key key_len ref rows Extra 
1 PRIMARY forum range PRIMARY PRIMARY 4 NULL 3 Using where; Using temporary; Using filesort 
1 PRIMARY category ref PRIMARY,forum_id forum_id 4 source_forum.forum.id 2 
1 PRIMARY board ref PRIMARY,category_id category_id 4 source_forum.category.id 4 Using where 
1 PRIMARY topic ref PRIMARY,board_id board_id 4 source_forum.board.id 58 
1 PRIMARY post ref PRIMARY,topic_id,trash topic_id 4 source_forum.topic.id 16 Using where 
3 DEPENDENT SUBQUERY post index topic_id created 4 NULL 1 Using where 
2 DEPENDENT SUBQUERY group_assoc ref board_id,group_id board_id 4 source_forum.board.id 4 Using where 

L'être utilisé, il compte le plus est rangée 56 ...

mise à jour

Ma requête:

SELECT 
    COUNT(id) AS num 
FROM (
    SELECT topic.*, 
     (SELECT created FROM post WHERE topic_id = topic.id ORDER BY created DESC LIMIT 1) AS lastpost 
    FROM topic 
    WHERE board_id = 6 AND 
    NOT EXISTS(SELECT id FROM topic_read_assoc WHERE topic_id = topic.id AND member_id = 489)    
    ) tab 
WHERE last_post_time > 1288032259; 

EXPLIQUER étendu

id select_type table type possible_keys key key_len ref rows filtered Extra 
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 440 100.00 Using where 
2 DERIVED topic ref board_id board_id 4 429 100.00 Using where 
4 DEPENDENT SUBQUERY topic_read_assoc ref topic_id,member_id topic_id 4 source_forum.topic.id 6 100.00 Using where 
3 DEPENDENT SUBQUERY post index topic_id created 4 NULL 1 1600.00 Using where 

Qu'est-ce que signifie filtré?

Répondre

1

Pouvez-vous publier la requête et les instructions SHOW CREATE TABLE aussi?

58 en effet n'est pas élevé, mais vous utilisez des tables temporaires ET un fichier de type. Et comme tous vos types sont ref et non eq_ref, vous devez multiplier ces valeurs: 3 * 2 * 4 * 58 * 16 * 1 * 4 = 89k lignes jointes (voir les lignes examinées - certaines tables ont probablement été entièrement numérisées - voir le USING WHERE commenter)

Pouvez-vous poster un EXPLAIN EXTENDED et SHOW WARNINGS?

+0

Quelle est la différence entre 'ref' et' eq_ref'? – Webnet

+0

@Webnet http://stackoverflow.com/a/1159772/334966 – mattalxndr

Questions connexes