Câu hỏi phỏng vấn MySQL
Câu hỏi

What is difference between horizontal and vertical partitioning...

Câu trả lời

Horizontal and vertical partitioning are two techniques used in databases to distribute data across multiple tables or databases, which are key strategies for managing large datasets and improving performance, scalability, and manageability.

Horizontal Partitioning (Sharding):

  • Concept: In horizontal partitioning, the rows of a table are divided across multiple tables or databases. Each partition (or shard) holds a subset of the rows but the same columns as the original table.
  • When to Use: It's used to improve performance and manageability when dealing with a large number of rows.
  • Example: If you have a table Users with columns UserID, Name, Country, you might divide this table into multiple tables based on Country. For example, all users from the USA in one table, users from the UK in another, and so on. Each partitioned table has the same columns (UserID, Name, Country), but only a portion of the rows.
  • Use Case: Horizontal partitioning is useful for handling large volumes of data with many rows. It enhances scalability by distributing the data across multiple servers (shards) and can significantly improve query performance in scenarios with large datasets by reducing the number of rows scanned[1][2].

Vertical Partitioning:

  • Concept: In vertical partitioning, the columns of a table are divided into multiple tables. Each partition holds a subset of the columns and all rows.
  • When to Use: Useful when a table has many columns, and queries often access only a subset of those columns. It helps in reducing I/O by loading only the necessary columns.
  • Example: Continuing with the Users table example (UserID, Name, Country), in vertical partitioning, you might split this into two tables: One table with UserID and Name, another table with UserID, Country. The UserID column is common in both tables and acts as a link between them.
  • Use Case: Vertical partitioning is beneficial when the table has many columns, and different queries access different subsets of these columns. It can i...
expert

expert

Gợi ý câu hỏi phỏng vấn

expert

How many tables can a trigger associate to in MySQL? Can a trigger be associated to a view?

senior

What is Memory Storage Engine in MySQL? What are heap tables?

senior

Compare MySQL and PostgresSQL

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào