<bdo id='J4TqC'></bdo><ul id='J4TqC'></ul>

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

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

        <legend id='J4TqC'><style id='J4TqC'><dir id='J4TqC'><q id='J4TqC'></q></dir></style></legend>
      1. MySQL 中的默认排序顺序(ALTER TABLE ... ORDER BY ...;)

        时间:2023-06-24

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

            • <legend id='umRM0'><style id='umRM0'><dir id='umRM0'><q id='umRM0'></q></dir></style></legend>

                  <tbody id='umRM0'></tbody>

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

                <tfoot id='umRM0'></tfoot>
                  本文介绍了MySQL 中的默认排序顺序(ALTER TABLE ... ORDER BY ...;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设 MySQL 表 (ISAM) 的默认排序通过执行:

                  Assume that the default ordering of a MySQL-table (ISAM) is changed by executing:

                  ALTER TABLE tablename ORDER BY columnname ASC;
                  

                  从现在开始,假设我的查询中没有指定ORDER BY"(即SELECT * FROM tablename哪里......限制 10 个;")?

                  From now on, am I guaranteed to obtain records retrieved from the table in the order of "columnname ASC" assuming no "ORDER BY" is specified in my queries (i.e. "SELECT * FROM tablename WHERE ... LIMIT 10;")?

                  是否有我应该注意的极端情况?

                  Are there any corner-cases that I should be aware of?

                  更新 #1: 非常感谢 Quassnoi,他正确指出 INSERT 和 DELETE 弄乱了顺序.这导致我提出以下额外问题:

                  Update #1: Thanks a lot to Quassnoi who correctly pointed out that INSERTs and DELETEs messes up the ordering. This leads me to the following to extra questions:

                  • 更新呢?假设没有对表进行 INSERT 或 DELETE,只有更新 - 排序顺序是否完整?
                  • 假设进行了 INSERT 和 DELETE - 我如何再次重建"排序,比如每天一次(在这种特定情况下,表只每天更改一次,因此在更改完成后每天重建它应该仍然可以!).REPAIR TABLE 是否修复它,或者必须添加 do ALTER TABLE ... ORDER BY again?

                  推荐答案

                  来自 文档:

                  注意插入和删除后表格不会保持这个顺序

                  Note that the table does not remain in this order after inserts and deletes

                  实际上,如果您向该表发出 SELECT ... ORDER BYALTER TABLE 选项不会让您免于 filesort>,而是让 filesort 更快.

                  Actually, if you issue SELECT ... ORDER BY to this table, the option to ALTER TABLE won't spare you of filesort, but instead make filesort much faster.

                  对一个已经排序的集合进行排序相当于浏览这个集合以确保一切正常.

                  Sorting an already ordered set is equivalent to browsing this set to ensure everything is OK.

                  更新呢?假设没有对表进行 INSERT 或 DELETE,只有更新 - 排序顺序是否完整?

                  What about UPDATEs? Assume that no INSERTs or DELETEs are made to the table, but only updates - will the sort order be intact?

                  如果您的表不包含任何动态字段(例如 VARCHAR 或 'BLOB'),那么 很可能 MyISAM 不会移动它更新时.

                  If your table does not contain any dynamic fields (like VARCHAR or 'BLOB'), then most probably MyISAM will not move it when updating.

                  不过,如果我正在建造一座核电站或获得报酬的东西,我不会依赖这种行为.

                  假设进行了 INSERT 和 DELETE - 我如何再次重建"排序,比如说每天一次(在这种特定情况下,表只每天更改一次,因此在更改完成后每天重建它应该仍然可以!).REPAIR TABLE 是否修复它,或者必须添加 do ALTER TABLE ... ORDER BY again?

                  Assume that INSERTs and DELETEs are made - how do I "rebuild" the sorting again, say once a day (in this specific case the table only changes daily, so rebuilding it daily after the changes are done should still be OK!). Does REPAIR TABLE fix it, or must add do ALTER TABLE ... ORDER BY again?

                  您需要执行ALTER TABLE ... ORDER BY.

                  REPAIR 只是修复损坏表的物理结构.

                  REPAIR just fixes the physical structure of a corrupted table.

                  这篇关于MySQL 中的默认排序顺序(ALTER TABLE ... ORDER BY ...;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为 InnoDB 的 ALTER TABLE 优化 MySQL 下一篇:修改列 Vs 更改列

                  相关文章

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

                    <tfoot id='V5sOS'></tfoot>

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