Está en la página 1de 14

Group: ISEI06B

Subject: Distributed Databases


U2T3: Distributed Database Design

Today:

TOPIC: Implement fragmentation in a database

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

Review of fundamental definitions of

fragmentation

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

FRAGMENTACIÓN.
Fragmentation Es el Proceso de dividir una
tabla en fragmentos
It is the Process of dividing a table into smaller (partes) de menor tamaño.
fragments (parts). Types: Tipos:
1. Horizontal
1. Horizontal 2. Vertical
2. Vertical 3. Híbrida
Es importante notar que
3. Hybrid cada fragmento se
It is important to note that each fragment is stored in almacena en un sitio
diferente.
a different place. Nota: Una tabla puede
Note: A table can divide into N fragments and each dividir en N fragmentos y
cada fragmento sólo puede
fragment can only belong to one table. pertenecer a una tabla.

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

Distributed Query CONSULTA DISTRIBUIDA.


Muestra la información
It shows the information of the union of de la unión de las
diferentes
the different fragmentations, of the fragmentaciones, de las
distintas ubicaciones.
distinct locations.

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

Fragmentation Rules REGLAS DE FRAGMENTACIÓN


Durante el proceso de fragmentación
During the fragmentation process, these 3 principles must be se deben respetarse con 3 principios:
respected: 1. Completitud: Todos los datos de
1. COMPLETENESS: All the data in the source table must be la tabla origen deben estar
dentro de alguna fragmentación
within some fragmentation and only new records can be inserted
y solo se pueden insertar nuevos
into the source table. registros en la tabla origen.
2. RECONSTRUCTION: When joining all the fragments, it should 2. Reconstrucción: Al unir todos los
fragmentos, se debe mostrar los
show the same records as the source table.
mismos registros que la tabla
3. DISJUNCTION: The records should not be repeated in different origen.
fragmentations, they should only be present in one of them. 3. Disyunción: Los registros no
deben repetirse en diferentes
fragmentaciones, solo deben
estar presentes en una de ellas.

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

SBDD.
DDBS
Un sistema de bases de datos
A distributed database system is defined distribuidas se define como
una colección de múltiples
as a collection of multiple databases that bases de datos que se
are distributed over a communications distribuyen por una red de
comunicaciones y que están
network and that are logically related, relacionadas de manera
forming a single database with a single lógica, formando una única
base de datos con un solo
logical schema. esquema lógico.

EXERCISE01: Create database (ex01_oct22).

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

1. Create a new table (students – id, code, name) and fragment horizontally according to id (less than 6: group1, less than 11:
group2)
SQL statements Outcome
CREATE DATABASE ex01_oct22;
CREATE TABLE Students (
id int,
code int(10),
name varchar(20)
)
PARTITION BY RANGE (id) (PARTITION group01 VALUES less than (6),
PARTITION group02 VALUES less than (11));

2. Insert 10 records
SQL statements Outcome
INSERT INTO students VALUES (1,1001,'Fernanda',);
INSERT INTO students VALUES (2,1002,'Alejandro',);
INSERT INTO students VALUES (3,1003,'Erick',);
INSERT INTO students VALUES (4,1004,'Victor',);
INSERT INTO students VALUES (5,1005,'Michael',);
INSERT INTO students VALUES (6,1006,'Daniel',);
INSERT INTO students VALUES (7,1007,'Isabelle',);
INSERT INTO students VALUES (8,1008,'Silvia',);
INSERT INTO students VALUES (9,1009,'Alice',);
INSERT INTO students VALUES (10,1010,'Frida',);

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

3: Create View for each horizontal fragmentation.


SQL statements Outcome

Group_a

CREATE VIEW group_a AS SELECT * FROM students PARTITION (group01);


CREATE VIEW group_b AS SELECT * FROM students PARTITION (group02);

Group_b

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

EXERCISE02: Create database (ex02_oct22).


1. Create a new table (students – id, code, name, age) and fragment horizontally according to age (less than 18: group1,
less than 40: group2)
SQL statements Outcome
CREATE DATABASE ex02_oct22;
CREATE TABLE Students (
id int,
code int(10),
name varchar(20),
age int
)
PARTITION BY RANGE (age) (PARTITION group01 VALUES less than (18),
PARTITION group02 VALUES less than (40));

2. Insert 10 records
SQL statements Outcome

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

INSERT INTO students VALUES (1,1001,'Fernanda',22);


INSERT INTO students VALUES (2,1002,'Alejandro',29);
INSERT INTO students VALUES (3,1003,'Erick',28);
INSERT INTO students VALUES (4,1004,'Victor',27);
INSERT INTO students VALUES (5,1005,'Michael',20);
INSERT INTO students VALUES (6,1006,'Daniel',39);
INSERT INTO students VALUES (7,1007,'Isabelle',16);
INSERT INTO students VALUES (8,1008,'Silvia',12);
INSERT INTO students VALUES (9,1009,'Alice',08);
INSERT INTO students VALUES (10,1010,'Frida',25);

3: Create View for each horizontal fragmentation.


SQL statements Outcome

CREATE VIEW group_a AS SELECT * FROM students PARTITION


(group01);
CREATE VIEW group_b AS SELECT * FROM students PARTITION
(group02);

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

Group_a

Group_b

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

EXERCISE03: Create database (ex03_oct22).


1. Create a new table (products – id, name, price) and fragment horizontally according to price (less than 100: group1, less
than 200: group2, less than 300: group3).
SQL statements Outcome
CREATE DATABASE ex03_oct22;
CREATE TABLE products (
id int,
name varchar(20),
price int
)
PARTITION BY RANGE (price) (PARTITION group01 VALUES less than (100),
PARTITION group02 VALUES less than (200),
PARTITION group03 VALUES less than (300));

2. Insert 10 records
SQL statements Outcome

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

INSERT INTO products VALUES (1,'Bolsa',220);


INSERT INTO products VALUES (2,'Sudadera',190);
INSERT INTO products VALUES (3,'Pantalon',280);
INSERT INTO products VALUES (4,'Falda',170);
INSERT INTO products VALUES (5,'Perfume',200);
INSERT INTO products VALUES (6,'Gorro',290);
INSERT INTO products VALUES (7,'Plumones',60);
INSERT INTO products VALUES (8,'Papitas',20);
INSERT INTO products VALUES (9,'Libro',80);
INSERT INTO products VALUES (10,'Plumon',25);

3: Create View for each horizontal fragmentation.


SQL statements Outcome

CREATE VIEW group_a AS SELECT * FROM products


PARTITION (group01);
CREATE VIEW group_b AS SELECT * FROM products
PARTITION (group02);
CREATE VIEW group_c AS SELECT * FROM products
PARTITION (group03);

Group_a

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)


Group: ISEI06B
Subject: Distributed Databases
U2T3: Distributed Database Design

Group_b

Group_c

Profesor: M. Alejandro Israel Romo Martínez (alejandro.romo@upa.edu.mx)

También podría gustarte