在没有ORDER BY的情况下使用LIMIT是否安全? [英] Is it safe to use LIMIT without ORDER BY

查看:228
本文介绍了在没有ORDER BY的情况下使用LIMIT是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用InnoDB.我需要查询从表中获取10条记录的顺序是任意的.

I'm using InnoDB. I need to query to get 10 records from a table is any order.

在没有ORDER BY的情况下使用LIMIT是否安全?会更快吗?

Is it safe to use LIMIT without ORDER BY? Would it be faster?

推荐答案

如果您不使用ORDER BY,那么您就不会对记录进行排序,因此肯定可以使数据检索更快.因此,如果仅使用LIMIT,则与通过ORDER BY检索的数据相比,速度会更快.但是请注意,在这种情况下,数据将不会处于任何顺序.

If you are not using the ORDER BY then you are not sorting your records, so it will definitely make your data retrieval faster. So if you simply use LIMIT then it would be faster as compared to the data retrieved through ORDER BY. But do note that in that case then case the data will not be in any order.

就安全性而言,我不确定您在考虑哪种安全性,因为在仅使用LIMIT且不使用ORDER BY子句的查询中没有潜在的危害.

As far as the safety is concerned, I am not sure about which safety you are thinking of, as there is no potential harm in a query which uses only LIMIT and does not uses an ORDER BY clause.

您还可以查看以下文章: ORDER BY…LIMIT性能优化

You can also look at the article: ORDER BY … LIMIT Performance Optimization

这篇关于在没有ORDER BY的情况下使用LIMIT是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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