tecnologia dei db server 1

37
Fragmentation Types Horizontal Vertical 1

Upload: others

Post on 08-Jan-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tecnologia dei DB server 1

Fragmentation Types

Horizontal

Vertical

1

Page 2: Tecnologia dei DB server 1

Transparency Levels

• Fragmentation Transparency

• Allocation Transparency

• Language Transparency

• No Transparency

2

Page 3: Tecnologia dei DB server 1

Football PlayersConsider the database fragmented according to the Country where a team belongs:

PLAYER ( Name, Team, Country, Role )

GOAL ( PlayerName, GameDate, Minute, GoalType, Description )

The GOAL table describes the goals scored by the various players during their career and has a fragmentation which is derived from that of PLAYER. Assume that names identify players.

Describe at the three transparency levels the required SQL statements for changing the player's team. Assume that you know the player's name and the destination team and country, while his role is unchanged.

3

Page 4: Tecnologia dei DB server 1

Two different cases

(a) The old and new team are in the same country

(b) The old and new team are in different countries

4

(a) Marco Borriello Milan -> Rome

(b) Zlatan Ibrahimovich Barcelona -> Milan

Page 5: Tecnologia dei DB server 1

Two different cases

(a) The old and new team are in the same country

(b) The old and new team are in different countries

5

Borriello Milan -> Rome

upadate Playerset Team = “Rome”where name = “Marco Borriello” // Fragmention transparency

upadate ItalianPlayerset Team = “Rome”where name = “Marco Borriello” // Allocation transparency

Page 6: Tecnologia dei DB server 1

Two different cases

(a) The old and new team are in the same country

(b) The old and new team are in different countries

6

Borriello Milan -> Rome

upadate Playerset Team = “Rome”where name = “Marco Borriello” // Fragmention transparency

upadate ItalianPlayerset Team = “Rome”where name = “Marco Borriello” // Allocation transparency

Page 7: Tecnologia dei DB server 1

Two different cases

(a) The old and new team are in the same country

(b) The old and new team are in different countries

7

Zlatan Ibrahimovich Barcelona -> Milan

upadate Playerset Team = “Milan”where name = “Zlatan Ibrahimovich” // Fragmention transparency

Allocation transparency ?

Page 8: Tecnologia dei DB server 1

8

create table GoalsScoredEverSinceByPlayersCurrentlyEnrolledInItaly( PlayerName varchar(50) references Player(Name) on update cascade on delete no action ... )

create table GoalsScoredEverSinceByPlayersCurrentlyEnrolledInSpain( PlayerName varchar(50) references Player(Name) on update cascade on delete no action ... )

Insert Zlatan’s data into ItalianPlayer

Insert all of Zlatan’s goals into the italian goal record (taken from the spanish one) -> Goals..Italy

Delete goals from the Goals..Spain table

Delete Zlatan from SpanishPlayer

Page 9: Tecnologia dei DB server 1

9

insert into ItalianPlayer select Name, ‘Milan', ‘Italy', Role from SpanishPlayer where Name = ‘Zlatan Ibrahimovic'

insert into Goals..Italy select * from Goals..Spain where PlayerName = ‘Zlatan Ibrahimovic‘

delete from Goals..Spain where PlayerName = ‘Zlatan Ibrahimovic‘

delete from SpanishPlayerwhere Name = ‘Zlatan Ibrahimovic‘

Page 10: Tecnologia dei DB server 1

10

L

Consider the data base:

Production(SerialNumber,PartType,Model,Quantity,Machine)

Pickup(SerialNumber,Lot,Customer,SalesPerson,Amount)

Customer(Name,City,Address)

SalesPerson(Name,City,Address)

Page 11: Tecnologia dei DB server 1

11

Design the horizontal fragmentation of the table Production and Pickup depending on the PartType value (‘Keyboard’, ‘Screen’, ‘CPU-box’ e ‘Cable’), assuming four Production centres (one for each component) located in Milan, Turin, Rome and Naples, and of Customer and SalesPerson on three Cities: Milan, Turin, Rome.

Page 12: Tecnologia dei DB server 1

12

The distributed DB contains the following tables

ProductionMiKbr(SerialNumber,PartType, Model,Quantity,Machine) ProductionToScr(SerialNumber,PartType, Model,Quantity,Machine)ProductionRmCpu(SerialNumber,PartType, Model,Quantity,Machine)ProductionNaCbl(SerialNumber,PartType, Model,Quantity,Machine)

Production = ProductionMiKbr ProductionToScr ProductionRmCpu ProductionNaCpl

Page 13: Tecnologia dei DB server 1

13

PickupMiKbr(SerialNumber,Lot,Client,SalesPerson,Amount)

PickupToScr(SerialNumber,Lot,Client,SalesPerson,Amount)

PickupRmCpu(SerialNumber,Lot,Client,SalesPerson,Amount)

PickupNaCbl(SerialNumber,Lot,Client,SalesPerson,Amount)

Pickup = PickupMiKbr PickupToScr PickupRmCpu PickupNaCpl

Page 14: Tecnologia dei DB server 1

14

ClientMi(Name,City,Address)ClientTo(Name,City,Address)ClientRm(Name,City,Address)

Client = ClientMi ClientTo ClientRm

Page 15: Tecnologia dei DB server 1

15

SalesPersonMi(Name,City,Address)SalesPersonTo(Name,City,Address)SalesPersonRm(Name,City,Address)

SalesPerson = SalesPersonMi SalesPersonTo SalesPersonRm

Page 16: Tecnologia dei DB server 1

16

Express the following queries at transparency levels of fragmentation, allocation and language:

Determine the available quantity of the product ’77Y6878’

Page 17: Tecnologia dei DB server 1

17

Transparency of fragmentation

SELECT QuantityFROM ProductionWHERE SerialNumber=’77Y6878’

Page 18: Tecnologia dei DB server 1

18

Transparency of allocationSELECT Quantity FROM ProductionMiKbrWHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionToScr WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionRmCpu WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionNaCbl WHERE SerialNumber=’77Y6878’)

Page 19: Tecnologia dei DB server 1

19

Transparency of allocationSELECT Quantity FROM ProductionMiKbrWHERE SerialNumber=’77Y6878’IF :empty then (SELECT Quantity FROM ProductionToScr WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionRmCpu WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionNaCbl WHERE SerialNumber=’77Y6878’)

Page 20: Tecnologia dei DB server 1

20

Transparency of languageSELECT Quantity FROM ProductionMiKbr@MilanWHERE SerialNumber=’77Y6878’SELECT Quantity FROM ProductionToScr@Turin WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionRmCpu@Rome WHERE SerialNumber=’77Y6878’ UNION SELECT Quantity FROM ProductionNaCbl@Naples WHERE SerialNumber=’77Y6878’

Page 21: Tecnologia dei DB server 1

21

Determine the clients who have bought a lot from the SalesPerson ‘Bianchi’, who has an office in Rome

Page 22: Tecnologia dei DB server 1

22

Transparency of fragmentation

SELECT Customer FROM PickupWHERE SalesPerson=‘Bianchi’

Page 23: Tecnologia dei DB server 1

23

Transparency of allocation

SELECT Client FROM PickupMiKbrWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupToScrWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupRmCpuWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupNaCblWHERE SalesPerson=‘Bianchi’

Page 24: Tecnologia dei DB server 1

24

Transparency of language

SELECT Client FROM PickupMiKbr@MilanWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupToScr@TurinWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupRmCpu@RomeWHERE SalesPerson=‘Bianchi’unionSELECT Client FROM PickupNaCbl@NaplesWHERE SalesPerson=‘Bianchi’

Page 25: Tecnologia dei DB server 1

25

Determine the machines used for the production of the parts type ‘Keyboard’ sold to the Customer ‘Rossi’

Page 26: Tecnologia dei DB server 1

26

Transparency of fragmentation

SELECT MachineFROM Production P1 JOIN Pickup P2 ON (P1.SerialNumber=P2.SerialNumber)WHERE Client = ‘Rossi’ AND PartType = ‘Keyboard’

Page 27: Tecnologia dei DB server 1

27

Transparency of allocationThis time the query is easier because only one fragment is totally dedicated to components of type ‘Keyboard’

SELECT MachineFROM ProductionMiKbr P1 JOIN PickupMiKbr P2 ON (P1.SerialNumber=P2.SerialNumber)WHERE Client = ‘Rossi’

Page 28: Tecnologia dei DB server 1

28

Transparency of language

Also this query is easier because only one fragment is totally dedicated to components of type ‘Keyboard’

SELECT MachineFROM ProductionMiKbr@Milan P1 JOIN PickupMiKbr@Milan P2 ON (P1.SerialNumber=P2.SerialNumber)WHERE Client = ‘Rossi’

Page 29: Tecnologia dei DB server 1

29

Update the Address of SalesPerson ‘Rossi’, moving from ‘via Po 45’ in ‘Milan’ to ‘Viale Trastevere 150’ in Rome’ (ignore the moving of related data in other tables)

Page 30: Tecnologia dei DB server 1

30

Transparency of fragmentation

UPDATE SalesPersonSET City = ‘Rome’, Address=‘VialeTrastevere 150’WHERE Name = ‘Rossi’

Page 31: Tecnologia dei DB server 1

31

Transparency of allocation

Delete followed by an Insert

DELETE FROM SalesPersonMiWHERE Name = ‘Rossi’

Insert INTO SalesPersonRmVALUES(‘Rossi’, ‘Rome’,

‘Viale Trastevere 150’)

Page 32: Tecnologia dei DB server 1

32

Transparency of language

Delete followed by an Insert

DELETE FROM SalesPersonMi@MilanWHERE Name = ‘Rossi’

Insert INTO SalesPersonRm@RomeVALUES(‘Rossi’, ‘Rome’,

‘Viale Trastevere 150’)

Page 33: Tecnologia dei DB server 1

33

Calcolate the sum of amounts of the orders received in Milan, Turin, Rome and Naples (note that the aggregate functions are also distributable)

Page 34: Tecnologia dei DB server 1

34

Transparency of fragmentation

SELECT SUM(Amount)FROM Pickup

Page 35: Tecnologia dei DB server 1

35

Transparency of allocation

We need to identify the contribute of each fragment.

To do a sum of sums it is necessary to use a view.

Page 36: Tecnologia dei DB server 1

36

Transparency of allocation

CREATE VIEW TotalAm(Tot) ASSELECT SUM (Amount)FROM PickupMiKbrUNION ALLSELECT SUM (Amount)FROM PickupToScrUNION ALLSELECT SUM (Amount)FROM PickupRmCpuUNION ALLSELECT SUM (Amount)FROM PickupNaCbl

SELECT SUM(Tot) FROM TotalAm

Page 37: Tecnologia dei DB server 1

37

Transparency of languageCREATE VIEW TotalAm(Tot) ASSELECT SUM (Amount)FROM PickupMiKbr@MilanUNION ALLSELECT SUM (Amount)FROM PickupToScr@TurinUNION ALLSELECT SUM (Amount)FROM PickupRmCpu@RomeUNION ALLSELECT SUM (Amount)FROM PickupNaCbl@Naples

SELECT SUM(Tot) FROM TotalAm