Middle
What is the difference between vertical and horizontal partitioning?
sobes.tech AI
Answer from AI
Vertical partitioning divides the columns of a table, while horizontal partitioning divides the rows.
Vertical partitioning:
- Division by columns.
- Grouping related columns or separating rarely accessed columns.
- Helps reduce the size of rows read during a query, increasing performance.
- May lead to the need for JOIN operations to retrieve all data of a row.
Horizontal partitioning (sharding):
- Division by rows.
- Data is divided based on a specific criterion (e.g., by ID, date).
- Allows distributing the load across multiple servers/nodes.
- Improves query performance as they process a smaller volume of data on a single node.
- Increases availability and scalability.
Comparison:
| Criterion | Vertical partitioning | Horizontal partitioning |
|---|---|---|
| What is divided | Columns | Rows |
| Main goal | Reducing row size, query optimization | Load distribution, scalability |
| Query complexity | JOINs for full rows | Distributed queries/routing |
| Data distribution | Within a single server | Between multiple servers/nodes |