0
這是問題很簡單,我知道,但我想有人解釋我看看我是否正確。MYSQL引擎如何工作查詢
這個簡單的查詢是否MYSQL總是執行從左到右的語義?
SELECT c03,c04,c05,count(*) as c FROM table
where status='Active' and c04 is not null and c05 is not null
group by c03,c04,c05
having c>1 order by c desc limit 10;
發動機開始從
* Status later comparing c04 and later c05
* Later groups the results
* later filters again the result applying the c>1 filter
* Later sorts and fetch the first 10 results and disposing the others
左至右過濾每一條記錄或者有一些其他的優化假設不使用索引...
但過濾器後的下一步是這樣嗎?後來分組結果 *稍後再次過濾應用c> 1過濾器的結果 *稍後分類並獲取前10個結果並處置其他結果 – chiperortiz
是的,我想是的(這是我的第二段提到的)。至少我認爲沒有可能以不同的順序去做。過濾必須在分組後進行。在過濾之前進行排序沒有任何意義,因爲過濾的複雜性是'O(n)',而排序需要'O(n log n)',所以優化器應該在排序之前減少結果集。挑選前10行只有在排序後纔可能。 – GhostGambler