MYSQL和LIMIT子句 [英] MYSQL and the LIMIT clause

查看:100
本文介绍了MYSQL和LIMIT子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否在查询中添加LIMIT 1可以加快处理速度?

I was wondering if adding a LIMIT 1 to a query would speed up the processing?

例如...

我有一个查询,该查询在大多数情况下会返回1个结果,但偶尔会返回10、100甚至1000的记录.但是我永远只想要第一张唱片.

I have a query that will most of the time return 1 result, but will occasionaly return 10's, 100's or even 1000's of records. But I will only ever want the first record.

极限1会加快速度还是没有改变?

Would the limit 1 speed things up or make no difference?

我知道我可以使用GROUP BY返回1个结果,但这只会增加更多计算量.

I know I could use GROUP BY to return 1 result but that would just add more computation.

任何想法都可以接受!

谢谢

推荐答案

这取决于您是否有ORDER BY.无论如何,ORDER BY都需要整个结果集,因此可以对其进行排序.

It depends if you have an ORDER BY. An ORDER BY needs the entire result set anyway, so it can be ordered.

如果您没有任何ORDER BY,它应该运行得更快.

If you don't have any ORDER BY it should run faster.

由于不需要发送整个结果集,因此在所有情况下它的运行速度至少要快一点.

It will in all cases run at least a bit faster since the entire result set needn't be sent of course.

这篇关于MYSQL和LIMIT子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆