用于检索“最受欢迎”的高效数据库设计表行
我计划创建一个 mysql 5 (myISAM) 表,其中包含 x 千行数据。每行都有一个计数字段,&具有 20 个最高计数值的行将被大量检索,可能与每行更新都是一对一的比例。通常不会检索不在这 20 行中的 x 千行。
选择查询前 20 个计数值的有效方法有哪些选择。数据不一定是实时的,但它很有帮助!
I am planning to create a mysql 5 (myISAM) table that will contain x thousand rows of data. Each row will have a count field, & the rows with the 20 highest count values will be retrieved quite a lot, probably on a one-for-one ratio to every row update. The x thousand rows not in this 20 will not typically be retrieved.
What are the choices wrt choosing an efficient method of querying for the 20 top count values. Data does not have to be realtime live but it helps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为count字段添加索引,然后就是普通的查询:
Add an index to the count field, then just a normal query:
在计数字段上创建索引。完毕。
Create an index on the count field. Done.
每五分钟清空一次,然后将前 20 个复制到单独的表中。要获得前 20 名,只需查阅该表即可。完毕!
(或者,您可以在接下来的几个小时内调整您的查询、参数和索引,使其一切“恰到好处”。)
Every five minutes, empty out and then copy the top 20 to a separate table. To get the top 20, just consult that table. Done!
(Or, you could spend the next few hours tweaking your query and parameters and indices and making it all "just right".)