V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
love
V2EX  ›  MySQL

数据库要实现一个固定大小的用户消息队列要怎做?(术语似乎是叫环形队列

  •  1
     
  •   love · 2021-02-05 15:24:10 +08:00 · 1113 次点击
    这是一个创建于 1147 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如有 10 万用户,每个用户每天要收 1000 消息到自己的队列,但只要保存最近 10000 条记录即可。

    类似表:

    userlog:
      id: int auto_increment
      user_id: int
      msg: varchar(100)
      time: datetime
    

    感觉每天循环处理每个用户然后批量删除 10000 条后的记录性能不太好的样式:

    DELETE FROM `userlog` 
    WHERE id IN (select id  FROM `userlog`  ORDER BY id DESC LIMIT 10000, 250))
    

    因为本身 mysql limit 语句要大偏移定位 10000 条记录后的记录就性能不好再加上还要每天给 10w 用户分别查询多次来删除。

    似乎没有好的办法啊?或者有不用 mysql 数据库的办法吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1240 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 17:58 · PVG 01:58 · LAX 10:58 · JFK 13:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.