禁用內嵌檢視的排序
MySQL會對group by欄位進行排序,但是一些內嵌檢視中的group by本身就是中間過程,沒有必要進行排序。
這種場景可以使用order by null禁用內嵌檢視的排序。
如下SQL
執行計劃:
使用Order By Null禁用排序
執行計劃:
可以看到執行計劃第四行,已經消除了排序。
參考:
http://hudeyong926.iteye.com/blog/785181
這種場景可以使用order by null禁用內嵌檢視的排序。
如下SQL
-
SELECT DISTINCT a.*, c.downNum
-
FROM sod_artist a INNER JOIN sod_artist_category_relation b ON a.ArtistID = b.ArtistID LEFT JOIN (SELECT d.ArtistID, COUNT(a.DownNum) AS downNum
-
FROM (SELECT downnum, songid
-
FROM sod_song_ranking1
-
WHERE SongDate = 20140422
-
) a INNER JOIN sod_song_artist_relation d ON a.SongID = d.SongID
-
GROUP BY d.ArtistID
-
) c ON a.ArtistID = c.ArtistID
-
WHERE a.State = 1
-
AND b.CategoryID = 1363
-
OR b.CategoryID = 1628
-
ORDER BY c.downNum DESC
- LIMIT 0, 45
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
- | id | select_type | table | type | possible_keys | key | ref | rows | Extra |
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
- | 1 | PRIMARY | b | range | PRIMARY,Index_1 | PRIMARY | NULL | 286 | Using where; Using index; Using temporary; Using filesort |
- | 1 | PRIMARY | a | eq_ref | PRIMARY | PRIMARY | songod.b.ArtistID | 1 | Using where |
-
| 1 | PRIMARY |
| ref | | | songod.b.ArtistID | 10 | NULL | -
| 2 | DERIVED |
| ALL | NULL | NULL | NULL | 55316 | Using temporary; Using filesort | - | 2 | DERIVED | d | ref | PRIMARY,inx_1 | inx_1 | a.songid | 1 | Using index |
- | 3 | DERIVED | sod_song_ranking1 | ref | songdate | songdate | const | 55316 | NULL |
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
-
SELECT DISTINCT a.*, c.downNum
-
FROM sod_artist a INNER JOIN sod_artist_category_relation b ON a.ArtistID = b.ArtistID LEFT JOIN (SELECT d.ArtistID, COUNT(a.DownNum) AS downNum
-
FROM (SELECT downnum, songid
-
FROM sod_song_ranking1
-
WHERE SongDate = 20140422
-
) a INNER JOIN sod_song_artist_relation d ON a.SongID = d.SongID
- GROUP BY d.ArtistID order by null
-
) c ON a.ArtistID = c.ArtistID
-
WHERE a.State = 1
-
AND b.CategoryID = 1363
-
OR b.CategoryID = 1628
-
ORDER BY c.downNum DESC
- LIMIT 0, 45
可以看到執行計劃第四行,已經消除了排序。
-
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
- | id | select_type | table | type | possible_keys | key | ref | rows | Extra |
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
- | 1 | PRIMARY | b | range | PRIMARY,Index_1 | PRIMARY | NULL | 286 | Using where; Using index; Using temporary; Using filesort |
- | 1 | PRIMARY | a | eq_ref | PRIMARY | PRIMARY | songod.b.ArtistID | 1 | Using where |
-
| 1 | PRIMARY |
| ref | | | songod.b.ArtistID | 10 | NULL | -
| 2 | DERIVED |
| ALL | NULL | NULL | NULL | 55316 | Using temporary | - | 2 | DERIVED | d | ref | PRIMARY,inx_1 | inx_1 | a.songid | 1 | Using index |
- | 3 | DERIVED | sod_song_ranking1 | ref | songdate | songdate | const | 55316 | NULL |
- +----+-------------+-------------------+--------+-----------------+-------------+-------------------+-------+-----------------------------------------------------------+
-
參考:
http://hudeyong926.iteye.com/blog/785181
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-1149590/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 鑲嵌資料集工具小結(三)概檢視/OverviewsView
- Nginx 內嵌變數Nginx變數
- matplotlib視覺化番外篇pie()--內嵌環形餅圖視覺化
- 掌握Go型別內嵌:設計模式與架構的新視角Go型別設計模式架構
- MongoDB查詢內嵌文件MongoDB
- php禁用函式設定及檢視方法詳解PHP函式
- 使用iframe內嵌網頁的時候,如何做到內嵌網頁的高度自適應 有大用網頁
- 淺談小程式內嵌網頁及內嵌網頁跳轉分享實現網頁
- 排序--最大堆構造和堆排序(單步檢視過程)排序
- Spring Boot 內嵌容器 Tomcat / UndertowSpring BootTomcat
- 內嵌樣式標記style
- 小程式內嵌h5H5
- git檢視檔案內容Git
- Oracle與MySQL內嵌遊標的使用示例OracleMySql
- git檢視指定提交檔案的內容Git
- Linux基楚操作指引【檢視版本、檢視路徑、檢視內容、編輯檔案】Linux
- 客戶端內嵌Vue頁面客戶端Vue
- Android/iOS內嵌Unity開發示例AndroidiOSUnity
- C++內嵌彙編 教程1C++
- SVG 立方體內嵌路徑拼接SVG
- 檢視谷歌seo內容外掛谷歌
- SpringBoot原始碼解析-內嵌Tomcat容器的啟動Spring Boot原始碼Tomcat
- Netweaver的埠號和Spring boot內嵌的Tomcat埠Spring BootTomcat
- 可以把 FolkMQ 內嵌到 SpringBoot3 專案裡(可內嵌的訊息中介軟體,純血國產)MQSpring Boot
- 如何檢視Control File中儲存的內容
- 學習Tomcat(七)之Spring內嵌TomcatTomcatSpring
- AdWhirl:iPhone,Android軟體內嵌廣告iPhoneAndroid
- Linux 檢視檔案內容——bat 命令LinuxBAT
- gdb golang 檢視iface 內部結構Golang
- 11 UML中的邏輯檢視、程序檢視、實現檢視、部署檢視
- 常用的7個Linux檔案內容檢視命令!Linux
- 攜程小程式內嵌webview實踐指南WebView
- JDK中內嵌JS引擎介紹及使用JDKJS
- C指標原理(7)-C內嵌彙編指標
- C指標原理(8)-C內嵌彙編指標
- C指標原理(6)-C內嵌彙編指標
- Larvel 操作 MongoDB(對內嵌陣列增刪改)MongoDB陣列
- golang1.16內嵌靜態資源指南Golang
- 2分鐘學會CSS內嵌樣式CSS