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