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. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個是怎么回事????2. 在應用配置文件 app.php 中找不到’route_check_cache’配置項3. html按鍵開關如何提交我想需要的值到數(shù)據(jù)庫4. css - width設置為100%之后列表無法居中5. ios - vue-cli開發(fā)項目webstrom會在stylus樣式報錯,飆紅,請大神幫忙6. javascript - 一個頁面有四個圖片,翻頁的時候想固定住某個圖片然后翻頁,如何實現(xiàn)呢?7. css3 - 怎么感覺用 rem 開發(fā)的不多啊8. html5 - 用Egret寫的小游戲,怎么分享到微信呢?9. python - 在pyqt中做微信的機器人,要在表格中顯示微信好友的名字,卻顯示不出來,怎么解決?10. objective-c - 自定義導航條為類似美團的搜索欄樣式
