gpt4 book ai didi

mysql - 搜索唯一索引时应该限制吗?

转载 作者:可可西里 更新时间:2023-11-01 08:06:00 26 4
gpt4 key购买 nike

例如我有这个查询

SELECT * FROM `table` WHERE `id` = '5123'

在此查询中,它将搜索 ID 为 5123 的所有结果。但我只想返回 1 行,所以我可以将 LIMIT 1 添加到查询中。

但是假设id是一个唯一索引,那么它找到之后还会继续搜索结果吗?

最佳答案

没有。

索引所做的其中一件事正是您所建议的:

MySQL uses indexes for these operations:

  • To find the rows matching a WHERE clause quickly.
  • To eliminate rows from consideration. If there is a choice between multiple indexes, MySQL normally uses the index that finds the smallest number of rows (the most selective index).

来自 http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html

关于mysql - 搜索唯一索引时应该限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20683049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com