mysql - 為什么使用Group By對SQL的索引性能會有很大的影響
問題描述
為什么使用Group By對SQL的索引性能會有很大的影響?索引是不是能提升group by的性能?
還有一點關于SQL的疑問,為什么在使用模糊查詢的時候,%name%, 如果使用了前模糊,會使得索引沒有了效果,這個怎么理解,雖然模糊的知道可能是這樣的,但是找不到官方對此的說法。謝謝~
問題解答
回答1:“對索引性能有很大影響”是指什么?索引的時間太久了?但這似乎又和gruop by沒什么關系。
所以我猜你的問題是不是“索引是不是能提升group by的性能”?這個問題的因果關系好想更容易理解些,那如果是這個問題的話,可能下面這段話能給你一些提示:
SQL databases use two entirely different group by algorithms. Thefirst one, the hash algorithm, aggregates the input records in atemporary hash table. Once all input records are processed, the hashtable is returned as the result. The second algorithm, the sort/groupalgorithm, first sorts the input data by the grouping key so that therows of each group follow each other in immediate succession.Afterwards, the database just needs to aggregate them. In general,both algorithms need to materialize an intermediate state, so they arenot executed in a pipelined manner. Nevertheless the sort/groupalgorithm can use an index to avoid the sort operation, thus enablinga pipelined group by.
原文出處:Indexing Group By
相關文章:
1. 視頻文件不能播放,怎么辦?2. mysql - 把一個表中的數據count更新到另一個表里?3. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?4. mysql 查詢身份證號字段值有效的數據5. visual-studio - Python OpenCV: 奇怪的自動補全問題6. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處7. node.js - nodejs開發中常用的連接mysql的庫8. linux - Ubuntu下編譯Vim8(+python)無數次編譯失敗9. python - 爬蟲模擬登錄后,爬取csdn后臺文章列表遇到的問題10. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?
