MySQL-5.7-8.2.1.16 DISTINCT Optimization

DISTINCT combined with ORDER BY needs a temporary table in many cases.

与ORDER BY组合在一起的DISTINCT在很多情况下需要一个临时表。

Because DISTINCT may use GROUP BY, learn how MySQL works with columns in ORDER BY or HAVING clauses that are not part of the selected columns.

因为DISTINCT可能使用GROUP BY,学习MySQL如何处理ORDER BY或HAVING子句中不属于所选列的列。

See Section 12.20.3, “MySQL Handling of GROUP BY”.

In most cases, a DISTINCT clause can be considered as a special case of GROUP BY. For example, the following two queries are equivalent:

在大多数情况下,DISTINCT子句可以被视为GROUP BY的特殊情况。例如,下面两个查询是等价的:

Due to this equivalence, the optimizations applicable to GROUP BY queries can be also applied to queries with a DISTINCT clause.

由于这种等效性,适用于GROUP BY查询的优化也可以应用于带有DISTINCT子句的查询。

Thus, for more details on the optimization possibilities for DISTINCT queries,

因此,有关DISTINCT查询的优化可能性的更多细节

see Section 8.2.1.15, “GROUP BY Optimization”.

When combining LIMIT row_count with DISTINCT, MySQL stops as soon as it finds row_count unique rows.

当结合LIMIT row_count和DISTINCT时,MySQL一旦发现row_count唯一的行就会停止。

If you do not use columns from all tables named in a query, MySQL stops scanning any unused tables as soon as it finds the first match. In the following case, assuming that t1 is used before t2 (which you can check with EXPLAIN), MySQL stops reading from t2 (for any particular row in t1) when it finds the first row in t2:

如果您不使用查询中命名的所有表中的列,MySQL一旦发现第一个匹配项,就会停止扫描任何未使用的表。在下面的例子中,假设t1在t2之前使用(你可以用EXPLAIN检查),MySQL在发现t2中的第一行时停止从t2中读取(对于t1中的任何特定行):

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值