This article focuses on interviews. In interviews, you only need to answer the key points. You do not need to have a very in-depth answer to the framework. If you want to cope with the interview, it is enough. Grasp the key points.
Interviewer: Tell us about the design of sub-databases and sub-tables?
In MySQL, sharding and sharding are common database horizontal expansion technologies, which can improve the throughput and scalability of the database. The following will explain in detail the design of sub-databases and sub-tables in MySQL.
-
Sub-library design:
Database sharding is to split a large database into multiple small databases, with each database independently storing a part of the data. Branch database design can be determined based on business needs, data volume and load conditions.
- Vertical sub-database: allocate different tables to different databases according to functions or modules.
- Horizontal sharding: Allocate data rows to different databases according to certain rules of the data (such as range, hash, etc.).
In the design of sub-library, you need to pay attention to the following points:
- Cross-database transaction issues: Cross-database transactions may cause consistency problems, and distributed transactions or other solutions need to be used to ensure data consistency.
- Global uniqueness issue: If a globally unique ID or other identifier is required, a distributed ID generation algorithm can be used, such as the Snowflake algorithm.
- Cross-database query issues: In queries involving multiple databases, distributed query tools or data integration at the application layer need to be used.
-
Sub-table design:
Table splitting is to split a large table into multiple small tables, and each table independently stores a part of the data. Table design can be determined based on data volume, query frequency and load conditions.
- Vertical table partitioning: assign different columns to different tables according to functions or modules.
- water