mysql - 為什么使用Group By對SQL的索引性能會有很大的影響
問題描述
為什么使用Group By對SQL的索引性能會有很大的影響?索引是不是能提升group by的性能?
還有一點關(guān)于SQL的疑問,為什么在使用模糊查詢的時候,%name%, 如果使用了前模糊,會使得索引沒有了效果,這個怎么理解,雖然模糊的知道可能是這樣的,但是找不到官方對此的說法。謝謝~
問題解答
回答1:“對索引性能有很大影響”是指什么?索引的時間太久了?但這似乎又和gruop by沒什么關(guān)系。
所以我猜你的問題是不是“索引是不是能提升group by的性能”?這個問題的因果關(guān)系好想更容易理解些,那如果是這個問題的話,可能下面這段話能給你一些提示:
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
相關(guān)文章:
1. javascript - 移動端,當出現(xiàn)遮罩層的時候,遮罩層里有div是超出高度scroll的,怎么避免滑動div的時候,body跟隨滑動?2. dockerfile - 為什么docker容器啟動不了?3. javascript - 用rem寫的頁面,安卓手機顯示文字是正常的,蘋果顯示的文字是特別小的是為什么呢4. macos - mac下docker如何設(shè)置代理5. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應(yīng)6. javascript - webapp業(yè)務(wù)流程基本一致,多套主題(樣式基本不一樣,交互稍有偏差)管理,并且有不斷有新增主題,該如何設(shè)計組件化架構(gòu)?7. apache - 本地搭建wordpress權(quán)限問題8. 新手 - Python 爬蟲 問題 求助9. javascript - 從mysql獲取json數(shù)據(jù),前端怎么處理轉(zhuǎn)換解析json類型10. javascript - JS設(shè)置Video視頻對象的currentTime時出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...
