Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database partitioning - Horizontal vs Vertical - Difference between Normalization and Row Splitting?

I am trying to grasp the different concepts of Database Partitioning and this is what I understood of it:

Horizontal Partitioning/Sharding: Splitting a table into different table that will contain a subset of the rows that were in the initial table (an example that I have seen a lot if splitting a Users table by Continent, like a sub table for North America, another one for Europe, etc...). Each partition being in a different physical location (understand 'machine'). As I understood it, Horizontal Partitioning and Sharding are the exact same thing(?).

Vertical Partitioning: From what I understood (http://technet.microsoft.com/en-us/library/ms178148%28v=sql.105%29.aspx ), there are 2 sorts of Vertical Partitioning:

  • Normalization (which consists of removing redundancies from a the database by splitting tables and linking them with a foreign key).

  • Row Splitting, here is what I don't understand, what is the difference between Normalization and Row Splitting? In what those 2 techniques differ from each other?

I have also read in this post (Difference between scaling horizontally and vertically for databases ) that the difference between Horizontal Partitioning and Vertical Partitioning is that in the first you scale by adding more machines, while in the second one you scale by adding more power (CPU, RAM) to your existing machine, is that a correct definition? I thought that the core difference between those 2 techniques resides in the way you split your tables.

I am sorry for the load of questions but I am a bit confused as a lot of different websites that I have came across say different things.

Any help clarifying would be greatly appreciated. Any link to a clear and simple demonstration with a few tables would also be very helpful.

like image 346
dukable Avatar asked Dec 05 '13 00:12

dukable


People also ask

What is difference between vertical partitioning vs horizontal partitioning in database?

Vertical Partitioning vs Horizontal PartitioningVertical Partitioning stores tables &/or columns in a separate database or tables. Horizontal Partitioning (sharding) stores rows of a table in multiple database clusters.

What is difference between horizontal and vertical partitioning does MySQL support both horizontal and vertical partitioning?

Horizontal vs. Horizontal partitioning means that all rows matching the partitioning function will be assigned to different physical partitions. Vertical partitioning allows different table columns to be split into different physical partitions. Currently, MySQL supports horizontal partitioning but not vertical.

What is horizontal partitioning in database?

Horizontal partitioning (often called sharding). In this strategy, each partition is a separate data store, but all partitions have the same schema. Each partition is known as a shard and holds a specific subset of the data, such as all the orders for a specific set of customers.

What is row splitting?

Also known as "row splitting," vertical partitioning separates columns. For example, widely used columns are stored in one database, while columns that are accessed infrequently are stored in another. Master/Slave Partitioning. This simple method is used when viewing updates in real time is not critical.


2 Answers

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.

like image 118
Fabian Avatar answered Sep 23 '22 06:09

Fabian


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 and
phone , 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

like image 41
sameer sukumaran Avatar answered Sep 23 '22 06:09

sameer sukumaran