gpt4 book ai didi

mysql - 如何充分利用mysql中的索引?

转载 作者:行者123 更新时间:2023-11-29 16:58:19 24 4
gpt4 key购买 nike

我必须从大约有 100 万个条目的表中选择值。我的哪个查询会更有效?

查询1:

select * from table1 
where indexedcolumn1 < value1
and unindexedcolumn1 < value 2
and indexedcolumn2 < value2;

查询2:

select * from table1 
where indexedcolumn1 < value1
and indexedcolumn2 < value2
and unindexedcolumn1 < value 2;

如何充分利用索引?

最佳答案

  1. WHERE 子句中的条件(列)序列没有任何意义,因为 mySQL 查询优化器没有考虑它。因此(如上所述)您的查询是相同的。
  2. 使用 EXPLAIN(例如:explain select * from ....)命令来找出服务器执行查询的方式。在 google 上的官方文档中阅读有关解释 EXPLAIN 输出的更多信息(那里有很多关于 EXPLAIN 的好文章)。
  3. 尝试对未索引的列建立索引,因为这是提高查询性能的最佳(而且我猜也是唯一的)方法。一个未索引的列通常会毁掉所有其他的努力。

关于mysql - 如何充分利用mysql中的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52418737/

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