SQLAdvanced#scaling

What is partitioning and how does it differ from sharding?

Partitioning splits one table into segments inside the same database, letting the engine prune irrelevant partitions. Sharding spreads data across separate database servers to scale writes and storage.

Example
CREATE TABLE orders (id INT, order_date DATE)
PARTITION BY RANGE (YEAR(order_date)) (
  PARTITION p2025 VALUES LESS THAN (2026),
  PARTITION p2026 VALUES LESS THAN (2027)
);

Related Questions

1
SQLIntermediate#architecture

OLTP vs OLAP?

Open
2
SQLIntermediate#security

What is SQL injection and how do you prevent it?

Open
3
SQLAdvanced#aggregates

What is GROUP BY with ROLLUP?

Open