0
我有一個查詢,我轉身成功的視圖。但site_phrase sp
表似乎沒有使用列並遍歷表中的所有記錄。這是爲什麼?下面是該查詢:爲什麼我的查詢不使用這個索引?
EXPLAIN SELECT
`p`.`id` AS `id`,
`p`.`text` AS `phrase`,
`p`.`ignored` AS `ignored_phrase`,
`p`.`client_id` AS `client_id`,
`s`.`id` AS `site_id`,
`s`.`sub_domain` AS `sub_domain`,
`s`.`competitor` AS `competitor`,
`s`.`ignored` AS `ignored_site`,
`pc`.`id` AS `pc_id`,
`pc`.`name` AS `pc_name`,
`psc`.`id` AS `psc_id`,
`psc`.`name` AS `psc_name`,
`p`.`volume` AS `volume`,
MIN(`pos`.`position`) AS `position`,
`pos`.`id` AS `pos_id`
FROM `client` c
JOIN client_site cs ON cs.client_id = c.id
JOIN site s ON s.id = cs.site_id
JOIN site_phrase sp ON sp.site_id = s.id
JOIN phrase p ON p.id = sp.phrase_id
JOIN `position` pos ON pos.phrase_id = sp.phrase_id
AND pos.site_id = sp.site_id
LEFT JOIN `phrase_sub_category` `psc`
ON `psc`.`id` = `p`.`phrase_sub_category_id`
LEFT JOIN `phrase_category` `pc`
ON `pc`.`id` = `psc`.`phrase_category_id`
GROUP BY `p`.`id`,`s`.`id`,`serp`.`id`
ORDER BY `p`.`id`,`pos`.`position`
,這裏是輸出的屏幕截圖,上面的查詢得到,當我說明/描述它 http://img827.imageshack.us/img827/3336/indexsql.png
無論我如何改變上述以及如何表的順序,他們第一張或第二張桌子似乎總是在做某種表格掃描。在截圖的例子中,問題表是sp
。這些表是innoDB類型,並且在我加入的所有表上都有適當的索引和外鍵。任何見解都會有所幫助。
什麼是查詢? – FrustratedWithFormsDesigner 2010-10-01 17:07:56
上面所有連接的人。我剛剛刪除了我選擇的字段。解釋選擇.....就是這樣 – Nathan 2010-10-01 17:09:33