<i id='cheJd'><tr id='cheJd'><dt id='cheJd'><q id='cheJd'><span id='cheJd'><b id='cheJd'><form id='cheJd'><ins id='cheJd'></ins><ul id='cheJd'></ul><sub id='cheJd'></sub></form><legend id='cheJd'></legend><bdo id='cheJd'><pre id='cheJd'><center id='cheJd'></center></pre></bdo></b><th id='cheJd'></th></span></q></dt></tr></i><div id='cheJd'><tfoot id='cheJd'></tfoot><dl id='cheJd'><fieldset id='cheJd'></fieldset></dl></div>
      <tfoot id='cheJd'></tfoot>
    1. <small id='cheJd'></small><noframes id='cheJd'>

          <bdo id='cheJd'></bdo><ul id='cheJd'></ul>
        <legend id='cheJd'><style id='cheJd'><dir id='cheJd'><q id='cheJd'></q></dir></style></legend>

        在mysql中使用INDEXES的最大好处是什么?

        What are the biggest benefits of using INDEXES in mysql?(在mysql中使用INDEXES的最大好处是什么?)

        1. <legend id='JmyvX'><style id='JmyvX'><dir id='JmyvX'><q id='JmyvX'></q></dir></style></legend>
          1. <small id='JmyvX'></small><noframes id='JmyvX'>

                <bdo id='JmyvX'></bdo><ul id='JmyvX'></ul>
                <tfoot id='JmyvX'></tfoot>
              • <i id='JmyvX'><tr id='JmyvX'><dt id='JmyvX'><q id='JmyvX'><span id='JmyvX'><b id='JmyvX'><form id='JmyvX'><ins id='JmyvX'></ins><ul id='JmyvX'></ul><sub id='JmyvX'></sub></form><legend id='JmyvX'></legend><bdo id='JmyvX'><pre id='JmyvX'><center id='JmyvX'></center></pre></bdo></b><th id='JmyvX'></th></span></q></dt></tr></i><div id='JmyvX'><tfoot id='JmyvX'></tfoot><dl id='JmyvX'><fieldset id='JmyvX'></fieldset></dl></div>

                    <tbody id='JmyvX'></tbody>

                  本文介绍了在mysql中使用INDEXES的最大好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道我需要设置一个主键,并将任何应该唯一的东西设置为唯一键,但什么是索引,我该如何使用它们?

                  I know I need to have a primary key set, and to set anything that should be unique as a unique key, but what is an INDEX and how do I use them?

                  有什么好处?优点 &缺点?我注意到我可以使用或不使用它们,我应该什么时候使用?

                  What are the benefits? Pros & Cons? I notice I can either use them or not, when should I?

                  推荐答案

                  简答:
                  索引加速 SELECT 并减慢 INSERT 的速度.

                  Short answer:
                  Indexes speed up SELECT's and slow down INSERT's.

                  通常最好有索引,因为它们加快 select 的速度比减慢 insert 的速度要快.

                  Usually it's better to have indexes, because they speed up select more than they slow down insert.

                  UPDATE 上,如果在 WHERE 子句中使用索引字段,索引可以向上加快速度,如果你update 索引字段之一.

                  On an UPDATE the index can speed things way up if an indexed field is used in the WHERE clause and slow things down if you update one of the indexed fields.

                  您如何知道何时使用索引

                  SELECT 语句前添加 EXPLAIN.
                  像这样:

                  Add EXPLAIN in front of your SELECT statement.
                  Like so:

                  EXPLAIN SELECT * FROM table1 
                  WHERE unindexfield1 > unindexedfield2 
                  ORDER BY unindexedfield3
                  

                  将向您展示 MySQL 在每个未编入索引的字段上需要做多少工作.
                  使用这些信息,您可以决定是否值得添加索引.

                  Will show you how much work MySQL will have to do on each of the unindexed fields.
                  Using that info you can decide if it is worthwhile to add indexes or not.

                  explain 也可以告诉你是不是 drop 和 index 比较好

                  Explain can also tell you if it is better to drop and index

                  EXPLAIN SELECT * FROM table1 
                  WHERE indexedfield1 > indexedfield2 
                  ORDER BY indexedfield3
                  

                  如果选择的行很少,或者 MySQL 决定忽略索引(它不时这样做),那么您最好删除索引,因为它减慢了insert的速度,但没有加快select的速度.

                  If very little rows are selected, or MySQL decided to ignore the index (it does that from time to time) then you might as well drop the index, because it is slowing down your inserts but not speeding up your select's.

                  那也可能是你的 select 语句不够聪明.
                  (对不起,答案很复杂,我试图保持简单,但失败了).

                  Then again it might also be that your select statement is not clever enough.
                  (Sorry for the complexity in the answer, I was trying to keep it simple, but failed).

                  链接:
                  MySQL 索引 - 最佳做法是什么?

                  这篇关于在mysql中使用INDEXES的最大好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                  Does MySQL have time-based triggers?(MySQL 有基于时间的触发器吗?)
                  is it possible to call a sql script from a stored procedure in another sql script?(是否可以从另一个 sql 脚本中的存储过程调用 sql 脚本?)
                  Procedure to loop through comma separated string is not working(遍历逗号分隔字符串的过程不起作用)

                • <i id='LsNkR'><tr id='LsNkR'><dt id='LsNkR'><q id='LsNkR'><span id='LsNkR'><b id='LsNkR'><form id='LsNkR'><ins id='LsNkR'></ins><ul id='LsNkR'></ul><sub id='LsNkR'></sub></form><legend id='LsNkR'></legend><bdo id='LsNkR'><pre id='LsNkR'><center id='LsNkR'></center></pre></bdo></b><th id='LsNkR'></th></span></q></dt></tr></i><div id='LsNkR'><tfoot id='LsNkR'></tfoot><dl id='LsNkR'><fieldset id='LsNkR'></fieldset></dl></div>

                    <small id='LsNkR'></small><noframes id='LsNkR'>

                      • <bdo id='LsNkR'></bdo><ul id='LsNkR'></ul>
                          <tbody id='LsNkR'></tbody>
                      • <legend id='LsNkR'><style id='LsNkR'><dir id='LsNkR'><q id='LsNkR'></q></dir></style></legend>
                          1. <tfoot id='LsNkR'></tfoot>