Home  >  Article  >  Backend Development  >  MySql sub-table, how do large companies do it, how to do it efficiently, how to do joint table query between sub-tables?

MySql sub-table, how do large companies do it, how to do it efficiently, how to do joint table query between sub-tables?

WBOY
WBOYOriginal
2016-09-21 14:13:091375browse

Now I have two tables

A user table, fields such as uid, username, pwd, email... and

An article table with fields such as aid, subject, content, time, uid...

Get the latest 20 data fields of the article: uid, username, email, aid, subject, content, time

There are a few questions now:

1. Which of the following two methods is faster? I think it’s the second type

The first type: After php gets the data, it loops directly, takes out the uid each time, and then queries the user table information

The second type: direct left external query

2. In the case of separate tables, how to query the joint tables

Suppose the user table is divided into 5 tables, user1, user2, user3, user4, user5. If each table has 100,000 user data, if you use linked list query, what should be done fastest? If the latest article 20 Articles, the author information of the first 10 articles is in user1, and the author information of the last 10 articles is in user4. How should I query the linked list? Of course, the author information of the article is not known in advance in the table, and is mainly obtained based on the uid record of each article.

Reply content:

Now I have two tables

A user table, fields such as uid, username, pwd, email... and

An article table with fields such as aid, subject, content, time, uid...

Get the latest 20 data fields of the article: uid, username, email, aid, subject, content, time

There are a few questions now:

1. Which of the following two methods is faster? I think it’s the second type

The first one: After php gets the data, it loops directly, taking out the uid each time, and then querying the user table information

The second type: direct left external query

2. In the case of separate tables, how to query the joint tables

Suppose the user table is divided into 5 tables, user1, user2, user3, user4, user5. If each table has 100,000 user data, if you use linked list query, what should be done fastest? If the latest article 20 Articles, the author information of the first 10 articles is in user1, and the author information of the last 10 articles is in user4. How should I query the linked list? Of course, the author information of the article is not known in advance in the table, and is mainly obtained based on the uid record of each article.

  1. Second type

  2. https://segmentfault.com/q/10...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn