Can I somehow make that mysql inserts data in a way that the database keeps an predefined order?
我能否以某种方式使mysql插入数据,以使数据库保持预定义的顺序?
Let's say I make a highscore list. I could always use ORDER BY when selecting the stuff, but all the ordering in 1,000,000+ datasets takes alot of performance when a user browses the highscore list.
假设我做了一个高分数列表。在选择这些东西时,我总是可以使用ORDER BY,但是当用户浏览highscore列表时,100万+数据集中的所有排序都需要大量的性能。
My idea is now that I want to insert the data in a way, that the table is always ordered by score desc, so all the ORDER BY work doesn't have to happen when users browse the list.
我的想法是,现在我想要插入数据,表格总是由score desc排序,所以当用户浏览列表时,所有的工作顺序都不需要发生。
2 个解决方案
#1
0
Also there is another solution. If you store these much records in order by than there is tedious. Another way is you can create index on high score column so mysql internally create one index so when you try to fetch these record in order by than its performance is better than direct fetching query.
还有另一个解决方案。如果你把这些记录按顺序储存起来,那就太乏味了。另一种方法是,你可以在高分值列上创建索引,这样mysql就可以在内部创建一个索引,所以当你试图按顺序获取这些记录时,它的性能比直接抓取查询要好。
Please create index of high score column.
请创建高分值列的索引。
#2
2
Tables have no inherent order that you should rely upon (they may, by coincidence, return rows in the same order that they were inserted, or by primary key sort order), so if you need a particular order, you should always use an ORDER BY
clause.
表没有您应该依赖的固有顺序(它们可能,碰巧的是,按照它们被插入的顺序,或者按主键排序顺序返回行),所以如果您需要一个特定的顺序,那么您应该总是使用order by子句。
However, the system may be able to perform the ordering more cheaply if it has an index available on the column on which you will have your ORDER BY
clause - so add an index:
但是,如果该系统在您的ORDER BY子句中有一个可用的索引,那么该系统可以更便宜地执行订购,因此添加一个索引:
CREATE INDEX IX_Table_Scores ON `Table` (score desc);
#1
0
Also there is another solution. If you store these much records in order by than there is tedious. Another way is you can create index on high score column so mysql internally create one index so when you try to fetch these record in order by than its performance is better than direct fetching query.
还有另一个解决方案。如果你把这些记录按顺序储存起来,那就太乏味了。另一种方法是,你可以在高分值列上创建索引,这样mysql就可以在内部创建一个索引,所以当你试图按顺序获取这些记录时,它的性能比直接抓取查询要好。
Please create index of high score column.
请创建高分值列的索引。
#2
2
Tables have no inherent order that you should rely upon (they may, by coincidence, return rows in the same order that they were inserted, or by primary key sort order), so if you need a particular order, you should always use an ORDER BY
clause.
表没有您应该依赖的固有顺序(它们可能,碰巧的是,按照它们被插入的顺序,或者按主键排序顺序返回行),所以如果您需要一个特定的顺序,那么您应该总是使用order by子句。
However, the system may be able to perform the ordering more cheaply if it has an index available on the column on which you will have your ORDER BY
clause - so add an index:
但是,如果该系统在您的ORDER BY子句中有一个可用的索引,那么该系统可以更便宜地执行订购,因此添加一个索引:
CREATE INDEX IX_Table_Scores ON `Table` (score desc);