当前位置:网站首页>Design a MySQL table for message queue to store message data

Design a MySQL table for message queue to store message data

2022-06-12 00:07:00 InfoQ

【 Job requirements 】
1.  Include table name 、 Field 、 Indexes ;
2.  Use words to describe the design ideas and reasons , for example : Why design an index ?
3.  One page  PPT  that will do .
【 Tips 】
1.  You need to consider one table per message queue , Or put all the messages in one table , Add a “ Queue name ” Field of .

【 analysis 】
Consider that messages are stored in db It could be a long time , If you put it in a separate table , Sooner or later, the amount of data in a single table will be large enough to affect db Performance of , Therefore, it can be done by queue name hash, Different queues hash To different table stores ; You can also create a separate mapping table from the queue name to the message table name. Each time you read or write, you can obtain the table name of the message table through this table . For simplicity, first use the queue name hash Divide the tables .
【 Design 】
Message storage table :
id:  Self increasing   Primary key
Queue name : Indexes
The message content
Insert time

Message consumption table :
id:  Self increasing   gradually
client_id:  Indexes
Queue name : Indexes
Last consumption id


原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120006469242.html