是否使用"LIMIT 1"加快对主键的查询? [英] Does using "LIMIT 1" speed up a query on a primary key?

查看:316
本文介绍了是否使用"LIMIT 1"加快对主键的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个主键说id,并且我对该键进行了简单的查询,例如,

If I have a primary key of say id and I do a simple query for the key such as,

SELECT id FROM myTable WHERE id = X

它将查找一行然后停止查找,因为它是主键,还是最好告诉mysql通过使用LIMIT 1限制其选择?例如:

Will it find one row and then stop looking as it is a primary key, or would it be better to tell mysql to limit its select by using LIMIT 1? For instance:

SELECT id FROM myTable WHERE id = X LIMIT 1

推荐答案

使用"LIMIT 1"是否可以加快对主键的查询?

Does using "LIMIT 1" speed up a query on a primary key?

不.如果没有LIMIT 1,它已经可以达到最快的速度.无论如何有效地暗示LIMIT 1.

No. It's already as fast as can be without LIMIT 1. LIMIT 1 is effectively implied anyway.

它将找到一行,然后停止查找,因为它是主键

Will it find one row and then stop looking as it is a primary key

是的

这里完全不需要表扫描:这是基于键的查找.找到匹配的行,该过程已结束.

No table scan should be necessary at all here: it's a key-based lookup. The matching row is found and that's the end of the procedure.

这篇关于是否使用"LIMIT 1"加快对主键的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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