用于检索“最受欢迎”的高效数据库设计表行

发布于 2024-08-20 00:01:44 字数 171 浏览 5 评论 0原文

我计划创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清晰传感 2024-08-27 00:01:44

为count字段添加索引,然后就是普通的查询:

SELECT * FROM myTable ORDER BY countField DESC LIMIT 20;

Add an index to the count field, then just a normal query:

SELECT * FROM myTable ORDER BY countField DESC LIMIT 20;
耶耶耶 2024-08-27 00:01:44

在计数字段上创建索引。完毕。

Create an index on the count field. Done.

梅倚清风 2024-08-27 00:01:44

每五分钟清空一次,然后将前 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".)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文