0% found this document useful (0 votes)
3 views

DB partitioning

The document explains database partitioning, detailing its types, including horizontal and vertical partitioning, and differentiating it from sharding. It covers the pros and cons of partitioning, such as improved query performance and challenges with updates and schema changes. A demo using Postgres is also mentioned to illustrate the concept.

Uploaded by

burzik2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DB partitioning

The document explains database partitioning, detailing its types, including horizontal and vertical partitioning, and differentiating it from sharding. It covers the pros and cons of partitioning, such as improved query performance and challenges with updates and schema changes. A demo using Postgres is also mentioned to illustrate the concept.

Uploaded by

burzik2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Partitioning

husseinnasser.com

Database Partitioning Explained


Agenda

● What is Partitioning?
● Horizontal Partitioning vs Vertical Partitioning
● Partitioning Types
● Partitioning vs Sharding
● Demo
● Pros & Cons
● Summary
CUSTOMERS Table
What is Partitioning?
id NAME

1 Ali

SELECT Name 2 Mike


FROM CUSTOMERS_TABLE
WHERE ID = 700,001
3 Edmond

.. ….

... ...

700,001 Kim

700,002 Ali

.. ...

1M James
CUSTOMERS_200K
id NAME
What is Partitioning? 1 Ali CUSTOMERS_800K
... .. id NAME
SELECT Name
FROM CUSTOMERS_TABLE 200,000 Edmond 600,001 Nada
WHERE ID = 700,001
... ..
CUSTOMERS_400K
Which “partition” is customer 700,001
700,001 Kim
in? id NAME
Partition CUSTOMERS_800K ... ...
200,001 James

800,000 Tyler
... ..

400,000 Smith

Split 1 million rows table CUSTOMERS_1M


CUSTOMERS_600K
into 5 tables called id NAME
partitions.. Same schema id NAME
800,001 Paul
400,001 Nasser
... ..
... ..
1,000,000 Rick
600,000 Karen
Vertical vs Horizontal Partitioning

● Horizontal Partitioning splits rows into partitions


○ Range or list
● Vertical partitioning splits columns partitions
○ Large column (blob) that you can store in a slow
access drive in its own tablespace
Partitioning Types

● By Range
○ Dates, ids (e.g. by logdate or customerid from to)
● By List
○ Discrete values (e.g. states CA, AL, etc.) or zip codes
● By Hash
○ Hash functions (consistent hashing)
Horizontal Partitioning vs Sharding

● HP splits big table into multiple tables in the same


database, client is agnostic
● Sharding splits big table into multiple tables across
multiple database servers
● HP table name changes (or schema)
● Sharding everything is the same but server changes
Demo - Example with Postgres

● Spin up a postgres instance


● create a table and Insert 10 million rows
● Create partitions
Pros of Partitioning

● Improves query performance when accessing a single


partition
● Sequential scan vs scattered index scan
● Easy bulk loading (attach partition)
● Archive old data that are barely accessed into cheap
storage
Cons of Partitioning

● Updates that move rows from a partition to another (slow


or fail sometimes)
● Inefficient queries could accidently scan all partitions
resulting in slower performance
● Schema changes can be challenging (DBMS could
manage it though)
Summary

● What is Partitioning?
● Horizontal Partitioning vs Vertical Partitioning
● Partitioning Types
● Partitioning vs Sharding
● Pros & Cons

You might also like