- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
假设通过执行以下操作更改了 MySQL 表 (ISAM) 的默认顺序:
ALTER TABLE tablename ORDER BY columnname ASC;
从现在开始,假设我的查询中没有指定“ORDER BY”(即“SELECT * FROM tablename”),我是否保证按照“列名 ASC”的顺序从表中检索记录哪里...限制 10;")?
有什么我应该注意的极端情况吗?
更新#1:非常感谢 Quassnoi,他正确地指出了 INSERT 和 DELETE 会打乱顺序。这导致我提出以下额外问题:
最佳答案
来自 documentation :
Note that the table does not remain in this order after inserts and deletes
实际上,如果您向此表发出 SELECT ... ORDER BY
,则 ALTER TABLE
的选项不会让您免于 filesort
,而是使 filesort
更快。
对已经排序的集合进行排序相当于浏览这个集合以确保一切正常。
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
不会移动它更新时。
不过,如果我正在 build 一座核电站或我得到报酬的东西,我不会依赖这种行为。
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
只是修复损坏表的物理结构。
关于mysql - MySQL 中的默认排序顺序(ALTER TABLE ... ORDER BY ...;),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/725717/
我是一名优秀的程序员,十分优秀!