Let's discuss how each QQ has many different friends and how the database is designed is more convenient.

Source: Internet
Author: User
Tags add time field table database sharding
Let's discuss how each QQ has many different friends. how can the database be designed more conveniently? Let's discuss & nbsp; each QQ has many different friends. how can we design databases more conveniently? It should be beyond my capabilities. I want to see what everyone has & nbsp; idea... ------ solution -------------------- all the 10 thousand QQ accounts in a two-field table are mutual friends, the number of records is 0.1 billion, and in fact it won't even reach. ------ solution: let's discuss how every QQ has many different friends. how can we design the database more conveniently?
Let's discuss how each QQ has many different friends. how can the database be designed more conveniently?

It should be beyond my capabilities. I want to see what idea is...
------ Solution --------------------
A two-field table
10 thousand QQ accounts are all friends of each other, and the number of records is 0.1 billion.
In fact, it won't even reach a tenth.
------ Solution --------------------
Id myid friendid

Done.

This is the best setup method, with the lowest server requirements.


------ Solution --------------------
Two tables use one qq table and one relational table
------ Solution --------------------
1. QQ member table
A record for each user
Id, nickanme, etc.

2. QQ friends relationship table
Id, myid, friendid

3. QQ black name table
Id myid blackid

4. Information Table. table Sharding is recommended here.
Table sharding by region id. one information table is used for every 2000 tables. for example, if id = 5000 is used, the table sharding should be 5000/2000 and then rounded up, that is, 2. Therefore, the table should be message_0002.
Id fromid, toid, message, addtime.


------ Solution --------------------
A table.
Create table 'qq _ friends '(
'My _ id' bigint (13) not null,
'Friend _ id' bigint (13) not null,
'Is _ black_id 'tinyint (1) not null default '0 ',
'Add _ date' TIMESTAMP (10) not null,
Primary key ('My _ id', 'Friend _ id '),
KEY 'My _ id' ('My _ id '),
KEY 'add _ date' ('add _ date ')
) ENGINE = InnoDB default charset = utf8;

We recommend that you use InnoDB instead of table locks.
Abandon auto-increment ID (what do you use it? Arrange the size ?)
Primary key sets the combination of q id and friend ID.
Add the index respectively for the q id and add time.
Is_black_id (blacklist or not, which can be stored as 0, 1)
As said on the first floor, because of the cross-recorded records, 10 thousand QQ accounts are all friends of each other, and the number of records is also 0.1 billion (the actual number must be less than), but the database will also be amazing. Therefore, we need to consider Database Sharding or database cluster (one database every 1 million and one server for several databases)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.