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

    <bdo id='WD4nK'></bdo><ul id='WD4nK'></ul>
<tfoot id='WD4nK'></tfoot>

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

        在mysql中索引日期时间字段是个好主意吗?

        时间:2023-10-25
          <bdo id='9L68y'></bdo><ul id='9L68y'></ul>

            <small id='9L68y'></small><noframes id='9L68y'>

                1. <legend id='9L68y'><style id='9L68y'><dir id='9L68y'><q id='9L68y'></q></dir></style></legend>
                    <tbody id='9L68y'></tbody>

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

                  <tfoot id='9L68y'></tfoot>
                  本文介绍了在mysql中索引日期时间字段是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在设计一个大型数据库.在我的应用程序中,我将有很多行,例如我目前有一个包含 400 万条记录的表.我的大多数查询都使用 datetime 子句来选择数据.在mysql数据库中索引日期时间字段是个好主意吗?

                  I am working on designing a large database. In my application I will have many rows for example I currently have one table with 4 million records. Most of my queries use datetime clause to select data. Is it a good idea to index datetime fields in mysql database?

                  Select field1, field2,.....,field15
                  from table where field 20 between now() and now + 30 days 
                  

                  我正在努力保持我的数据库正常运行并且查询运行顺利

                  I am trying to keep my database working good and queries being run smoothly

                  更多,你认为我应该有什么想法来创建一个高效的数据库?

                  More, what idea do you think I should have to create a high efficiency database?

                  推荐答案

                  MySQL 建议使用索引的原因有很多,包括消除条件之间的行:http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

                  MySQL recommends using indexes for a variety of reasons including elimination of rows between conditions: http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

                  如果您打算在查询中频繁使用它,这将使您的日期时间列成为索引的绝佳候选者.如果您的唯一条件是 BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY) 并且您在条件中没有其他索引,则 MySQL 将不得不执行 全表扫描 在每个查询上.我不确定 30 天内生成了多少行,但只要少于总行数的 1/3 左右,在列上使用索引会更有效.

                  This makes your datetime column an excellent candidate for an index if you are going to be using it in conditions frequently in queries. If your only condition is BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 30 DAY) and you have no other index in the condition, MySQL will have to do a full table scan on every query. I'm not sure how many rows are generated in 30 days, but as long as it's less than about 1/3 of the total rows it will be more efficient to use an index on the column.

                  您关于创建高效数据库的问题非常广泛.我只想确保它已规范化并且所有适当的列都已编入索引(即在连接和 where 子句中使用的列).

                  Your question about creating an efficient database is very broad. I'd say to just make sure that it's normalized and all appropriate columns are indexed (i.e. ones used in joins and where clauses).

                  这篇关于在mysql中索引日期时间字段是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用mysql处理非常大的数据 下一篇:表扫描和聚集索引扫描有什么区别?

                  相关文章

                2. <small id='0hJHK'></small><noframes id='0hJHK'>

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

                      <legend id='0hJHK'><style id='0hJHK'><dir id='0hJHK'><q id='0hJHK'></q></dir></style></legend>