SELECT SUM(UcAmount) FROM memb_capitaldetail WHERE 1=1
and UserId='07d81732-be1b-41e2-a7d4-aad60161ee36'
SELECT count(UcAmount) FROM memb_capitaldetail WHERE 1=1
and UserId='07d81732-be1b-41e2-a7d4-aad60161ee36'
SELECT count(UserId) FROM memb_capitaldetail WHERE 1=1
and UserId='07d81732-be1b-41e2-a7d4-aad60161ee36'
AND InComeStatus=1
SELECT count(UserId) FROM memb_capitaldetail WHERE 1=1
and UserId='07d81732-be1b-41e2-a7d4-aad60161ee36'
我在memb_capitaldetail給UserId建立了索引,但是用expain發現,只有最后一個走了索引,其他都是全表掃描。
請問,這個是什么原因呢?
謝謝
uj5u.com熱心網友回復:
表結構和explain都貼出來uj5u.com熱心網友回復:
大致知道原因了,這個用戶ID查出的資料近4萬,總共資料16萬
uj5u.com熱心網友回復:
大致知道原因了,這個用戶ID查出的資料近4萬,總共資料16萬,應該是
如果我換成一個只查只有幾百條的確實走了。
uj5u.com熱心網友回復:
UserId上相同的記錄太多了。一般同一個值超20%MYSQL就不會走索引了,反而直接全表掃描了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/28400.html
標籤:MySQL
