[SQL ] Select Count速度很慢

作者: james999 (無傷大雅)   2020-10-23 13:47:37
(針對 SQL 語言的問題,用這個標題。請用 Ctrl+Y 砍掉這行)
資料庫名稱:SQLite
資料庫版本:3
內容/問題描述:
SELECT Count(*) FROM [tblHitRecordsDtl] inner join [tblHitRecords] on
[tblHitRecords].id = [tblHitRecordsDtl].hitRecId where
[tblHitRecordsDtl].rank = 1 and (recTime >= 1603419942778 and recTime <=
1604419942778)
其中,recTime是Integer型別。
當where條件後只有rank=1時,速度約500ms以下,但加上recTime的判斷後,
大約要花費3-4秒…
資料表只有5萬筆資料,想請問板上大神該如何解決呢? 謝謝。
作者: tedcat (動靜:MSN暱稱為主)   2020-10-23 20:57:00
做index
作者: sam0308   2020-10-23 21:42:00
不要用inner join 試試看
作者: MOONY135 (談無慾)   2020-10-25 01:02:00
先拿1做temp taBLE之後再用between呢

Links booklink

Contact Us: admin [ a t ] ucptt.com