1
我跑這兩個不同的查詢,我不明白爲什麼在第一個銷售表不使用索引爲什麼MySQL不使用索引
EXPLAIN SELECT COUNT(`sale`.`saleId`) AS `nb`
FROM `sale`
WHERE `sale`.`saleTransactionId` IN (
SELECT `transaction`.`transactionId`
FROM `transaction`
WHERE `transaction`.`transactionId` = 87587
)
結果是
result 1 http://snag.gy/SusqF.jpg
第二個
EXPLAIN SELECT COUNT(`sale`.`saleId`) AS `nb`
FROM `sale`
WHERE `sale`.`saleTransactionId` IN (87587)
結果是
result 2 http://snag.gy/ZgOXQ.jpg
中庸之道,以確保
SELECT `transaction`.`transactionId`
FROM `transaction`
WHERE `transaction`.`transactionId` = 87587
回報探微一行
saleTransactionId是INT(11)的transactionId 這兩個表使用的MyISAM
銷售指數結構
sale index structure http://snag.gy/we3HL.jpg
謝謝!