-1
任何人都可以調整此查詢以獲得更好的性能嗎?我該如何優化以下mysql查詢
SELECT `Vocabulary`.`id`, `Vocabulary`.`title`, `Vocabulary`.`alias`, `Vocabulary`.`description`, `Vocabulary`.`required`, `Vocabulary`.`multiple`, `Vocabulary`.`tags`, `Vocabulary`.`plugin`, `Vocabulary`.`weight`, `Vocabulary`.`updated`, `Vocabulary`.`created`, `TypesVocabulary`.`id`, `TypesVocabulary`.`type_id`, `TypesVocabulary`.`vocabulary_id`, `TypesVocabulary`.`weight` FROM `epowerg`.`vocabularies` AS `Vocabulary` JOIN `epowerg`.`types_vocabularies` AS `TypesVocabulary` ON (`TypesVocabulary`.`type_id` IN (1, 2, 4) AND `TypesVocabulary`.`vocabulary_id` = `Vocabulary`.`id`) ORDER BY `Vocabulary`.`weight` ASC;
結果從查詢生成:
+----+-------------+-----------------+------+---------------+------+---------+------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-----------------+------+---------------+------+---------+------+------+---------------------------------+ | 1 | SIMPLE | Vocabulary | ALL | PRIMARY | NULL | NULL | NULL | 2 | Using temporary; Using filesort | | 1 | SIMPLE | TypesVocabulary | ALL | NULL | NULL | NULL | NULL | 4 | Using where; Using join buffer | +----+-------------+-----------------+------+---------------+------+---------+------+------+---------------------------------+
預先感謝 普拉巴卡蘭。 [R
以什麼方式優化?,你有性能方面的原因嗎? –
將索引添加到'type_id' – Jens
爲什麼你認爲它需要調整?它看起來很好。 – tolanj