Database partitioning - Horizontal vs Vertical - Difference between Normalization and Row Splitting?
Solution 1:
Partitioning is a rather general concept and can be applied in many contexts. When it considers the partitioning of relational data, it usually refers to decomposing your tables either row-wise (horizontally) or column-wise (vertically).
Vertical partitioning, aka row splitting, uses the same splitting techniques as database normalization, but ususally the term (vertical / horizontal) data partitioning refers to a physical optimization whereas normalization is an optimization on the conceptual level.
Since you ask for a simple demonstration - assume you have a table like this:
create table data (
id integer primary key,
status char(1) not null,
data1 varchar2(10) not null,
data2 varchar2(10) not null);
One way to partition data
vertically: Split it as follows:
create table data_main (
id integer primary key,
status char(1) not null,
data1 varchar2(10) not null );
create table data_rarely_used (
id integer primary key,
data2 varchar2(10) not null,
foreign key (id) references data_main (id) );
This kind of partitioning can be applied, for example, when you rarely need column data2 in your queries. Partition data_main will take less space, hence full table scans will be faster and it is more likely that it fits into the DBMS' page cache. The downside: When you have to query all columns of data
, you obivously have to join the tables, which will be more expensive that querying the original table.
Notice you are splitting the columns in the same way as you would when you normalize tables. However, in this case data
could already be normalized to 3NF (and even BCNF and 4NF), but you decide to further split it for the reason of physical optimization.
One way to partition data
horizontally, using Oracle syntax:
create table data (
id integer primary key,
status char(1),
data1 varchar2(10),
data2 varchar2(10) )
partition by list (status) (
partition active_data values ( 'A' ),
partition other_data values(default)
);
This would tell the DBMS to internally store the table data
in two segments (like two tables), depending on the value of the column status
. This way of partitioning data
can be applied, for example, when you usually query only rows of one partition, e.g., the status 'A' rows (let's call them active rows). Like before, full scans will be faster (particularly if there are only few active rows), the active rows (and the other rows resp.) are stored contiguously (they won't be scattered around pages that they share with rows of a different status value, and it is more likely that the active rows will be in the page cache.
Solution 2:
Horizontal Partitioning in data base
Keeping all the fields EG:Table Employees
has
- id,
- name,
- Geographical location ,
- email,
- designation,
- phone
EG:1.Keeping all the fields and distributing records in multiple machines.say id= 1-100000 or 100000-200000 records in one machine each and distributing over multiple machines.
EG:2.Keeping separate databases for Regions EG: Asia Pacific,North America
Key:Picking set of rows based on a criteria
Vertical Partitioning in data base
It is similar to Normalization where the same table is divided in to multiple tables and used with joins if required.
EG:
id
, name
, designation
is put in one table andphone
, email
which may not be frequently accessed are put in another.
Key:Picking set of columns based on a criteria.
- Horizontal/Vertical Scaling is different from partitioning
Horizontal Scaling:
is about adding more machines to enable improved responsiveness and availability of any system including database.The idea is to distribute the work load to multiple machines.
Vertical Scaling:
is about adding more capability in the form of CPU,Memory to existing machine or machines to enable improved responsiveness and availability of any system including database.In a virtual machine set up it can be configured virtually instead of adding real physical machines.
Sameer Sukumaran