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)