La presentazione è in caricamento. Aspetta per favore

La presentazione è in caricamento. Aspetta per favore

Complementi di basi di dati Progetti ModelGen - MIDST P. Atzeni, P. Cappellari, G. Gianforme 15 marzo 2007.

Presentazioni simili


Presentazione sul tema: "Complementi di basi di dati Progetti ModelGen - MIDST P. Atzeni, P. Cappellari, G. Gianforme 15 marzo 2007."— Transcript della presentazione:

1 Complementi di basi di dati Progetti ModelGen - MIDST P. Atzeni, P. Cappellari, G. Gianforme 15 marzo 2007

2 P. Atzeni15 marzo 20072 Datalog Un linguaggio di programmazione logica per basi di dati derivato dal Prolog Utilizza predicati di due tipi: –estensionali: relazioni della base di dati –intensionali: corrispondono alle viste Il linguaggio è basato su regole utilizzate per "definire" i predicati estensionali

3 P. Atzeni15 marzo 20073 Datalog in ModelGen-MIDST In ModelGen-MIDST usiamo Datalog per materializzare i risultati delle traduzioni: –le regole generano i costrutti tradotti –La distinzione fra predicati intensionali e estensionali è leggermente diversa dal normale Utilizziamo unestensione importante: generazione di OID con funzioni di Skolem

4 P. Atzeni15 marzo 20074 Datalog, sintassi Regole: testa corpo –testa è un predicato atomico (intensionale) –corpo è una lista (congiunzione) di predicati atomici Le interrogazioni sono specificate per mezzo di predicati atomici (convenzionalmente preceduti da "?") Vediamo ora anche le interrogazioni, anche se per i progetti ci interessano poco (ci interessa definire dati derivati)

5 P. Atzeni15 marzo 20075 Esempi Impiegati NomeEtàStipendioMatricola Bianchi37385998 Rossi34457309 Bruni43425698 Neri42359553 Mori45504076 Lupi46608123 Supervisione ImpiegatoCapo 5998 7309 5698 9553 4076 5698 4076 8123

6 P. Atzeni15 marzo 20076 Esempio -1 Trovare matricola, nome, età e stipendio degli impiegati che hanno 30 anni SEL Età=30 (Impiegati) { Matricola: m, Nome: n, Età: e, Stipendio: s | Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s) s = 30 } ? Impiegati(Matricola: m, Nome: n, Età: 30, Stipendio: s)

7 P. Atzeni15 marzo 20077 Esempio 0a Trovare matricola, nome, età e stipendio degli impiegati che guadagnano più di 40 SEL Stipendio>40 (Impiegati) { Matricola: m, Nome: n, Età: e, Stipendio: s | Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s) s > 40 } Serve un predicato intensionale ImpRicchi(Matricola: m, Nome: n, Età: e, Stipendio: s) Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s), s >40 ? ImpRicchi(Matricola: m, Nome: n, Età: e, Stipendio: s)

8 P. Atzeni15 marzo 20078 Esempio 0b Trovare matricola, nome ed età di tutti gli impiegati PROJ Matricola, Nome, Età (Impiegati) { Matricola: m, Nome: n, Età: e | Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s)} InfoPubbliche(Matricola: m, Nome: n, Età: e) Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s) ? InfoPubbliche(Matricola: m, Nome: n, Età: e)

9 P. Atzeni15 marzo 20079 Esempio 2 Trovare le matricole dei capi degli impiegati che guadagnano più di 40 PROJ Capo (Supervisione JOIN Impiegato=Matricola (SEL Stipendio>40 (Impiegati))) { Capo: c | Supervisione(Capo:c,Impiegato:m) Impiegati(Matricola: m, Nome: n, Età: e, Stipendio: s) s > 40 } CapiDeiRicchi (Capo:c) ImpRicchi(Matricola: m, Nome: n, Età: e, Stipendio: s), Supervisione (Capo:c,Impiegato:m) ? CapiDeiRicchi (Capo:c)

10 P. Atzeni15 marzo 200710 Esempio 5 Trovare matricola e nome dei capi i cui impiegati guadagnano tutti più di 40 PROJ Capo (Supervisione) - PROJ Capo (Supervisione JOIN Impiegato=Matricola (SEL Stipendio 40 (Impiegati))) serve la negazione CapiDiNonRicchi (Capo:c) Supervisione (Capo:c,Impiegato:m), Impiegati (Matricola: m, Nome: n, Età: e, Stipendio: s), s 40 CapiSoloDiRicchi (Matricola: c, Nome: n) Impiegati (Matricola: c, Nome: n, Età: e, Stipendio: s), Supervisione (Capo:c,Impiegato:m), not CapiDiNonRicchi (Capo:c) ? CapiSoloDiRicchi (Matricola: c, Nome: n)

11 P. Atzeni15 marzo 200711 Esempio 6 Per ogni impiegato, trovare tutti i superiori. Serve la ricorsione Superiore (Impiegato: i, SuperCapo: c) Supervisione (Impiegato: i, Capo: c) Superiore (Impiegato: i, SuperCapo: c) Supervisione (Impiegato: i, Capo: c'), Superiore (Impiegato: c', SuperCapo: c)

12 P. Atzeni15 marzo 200712 Datalog, semantica La definizione della semantica delle regole ricorsive è delicata (in particolare con la negazione) Potere espressivo: –Datalog non ricorsivo senza negazione è equivalente al calcolo senza negazione e senza quantificatore universale –Datalog non ricorsivo con negazione è equivalente al calcolo e all'algebra –Datalog ricorsivo senza negazione e calcolo sono incomparabili –Datalog ricorsivo con negazione è più espressivo di calcolo e algebra

13 P. Atzeni15 marzo 200713 Datalog with OID invention Datalog (informally): –a logic programming language with no function symbols and predicates that correspond to relations in a database –we use a non-positional notation Datalog with OID invention: –an extension of Datalog that uses Skolem functions to generate new identifiers when needed Skolem functions: –injective functions that generate "new" values (value that do not appear anywhere else); so different Skolem functions have disjoint ranges

14 P. Atzeni15 marzo 200714 Esercizio Traduzione da ER a relazionale, completando quanto accennato nei lucidi seguenti Per questa volta ancora sulla carta, per ragionare sui concetti

15 P. Atzeni15 marzo 200715 A basic translation From (a simple) binary ER model to the relational model –a table for each entity –a column (in the table for E) for each attribute of an entity E –for each M:N relationship a table for the relationship columns … –for each 1:N and 1:1 relationship: a column for each attribute of the identifier …

16 P. Atzeni15 marzo 200716 A basic translation application Departments NameAddress Employees EmpNo Name Affiliation Departments 1,1 0,N Name Address Employees EmpNoNameAffiliation

17 P. Atzeni15 marzo 200717 A basic translation (in supermodel terms) From (a simple) binary ER model to the relational model –an aggregation of lexicals for each abstract –a component of the aggregation for each attribute of abstract –for each M:N aggregation of abstracts … … From (a simple) binary ER model to the relational model –a table for each entity –a column (in the table for E) for each attribute of an entity E –for each M:N relationship a table for the relationship columns … –for each 1:N and 1:1 relationship: a column for each attribute of the identifier …

18 P. Atzeni15 marzo 200718 Schemas in our dictionary SM-Abstract OIDSchemaName 3011Employees 3021Departments 2013Clerks 2023Offices SM-AttributeOfAbstract OIDSchemaNameisIdentisNullableTypeAbstrOID 4011EmpNoTFInt301 4021NameFFText301 4041NameTFChar302 4051AddressFFText302 5013CodeTFInt201 ………………… Employees Departments EmpNo Name Address

19 P. Atzeni15 marzo 200719 "An aggregation of lexicals for each abstract" SM_AggregationOfLexicals( OID: #aggregationOID_1(OID), Name: n) SM_Abstract ( OID: OID, Name: n ) ; the value for the attribute Name is copied (by using variable n) the value for OID is "invented": a new value for the function #aggregationOID_1(OID) for each different value of OID, so a different value for each value of SM_Abstract.OID the materialization of the Skolem function describes the mapping

20 P. Atzeni15 marzo 200720 "A component of the aggregation for each attribute of abstract" SM_ComponentOfAggregation… ( OID: #componentOID_1(attOID), Name: name, AggrOID: #aggregationOID_1(absOID), IsNullable: isNullable, IsKey: isIdent, Type : type ) SM_AttributeOfAbstract( OID: attOID, Name: name, AbstractOID: absOID, IsIdent: isIdent, IsNullable: isNullable, Type : type ) ; Skolem functions –are functions –are injective –have disjoint ranges the first function "generates" a new value the second "reuses" the value generated by the first rule

21 P. Atzeni15 marzo 200721 "An aggregation of lexicals for each abstract" SM_AggregationOfLexicals( OID: #aggregationOID_1(OID), Name: name) SM_Abstract ( OID: OID, Name: name ) ;

22 P. Atzeni15 marzo 200722 "An aggregation of lexicals for each abstract" SM_AggregationOfLexicals( OID: #aggregationOID_1(OID), Name: n) SM_Abstract ( OID: OID, Name: n ) ; the value for the attribute Name is copied (by using variable n) the value for OID is "invented": a new value for the function #aggregationOID_1(OID) for each different value of OID, so a different value for each value of SM_Abstract.OID

23 P. Atzeni15 marzo 200723 "An aggregation of lexicals for each abstract" SM-Abstract OIDSchemaName 3011Employees 3021Departments ……… SM-AttributeOfAbstract OIDSchemaNameisIdentisNullableTypeAbstrOID 4011EmpNoTFInt301 4021NameFFText301 ………………… Employees EmpNo Name 11 Departments1002 Employees1001 SM_AggregationOfLexicals( OID: #aggregationOID_1(OID), Name: n) SM_Abstract ( OID: OID, Name: n ) ; … 3021002 …… 1001 SM-AggregationOfLexicals SchemaNameOID SM-aggregationOID_1_SK absOIDOID 301 Employees

24 P. Atzeni15 marzo 200724 "A component of the aggregation for each attribute of abstract" SM_ComponentOfAggregation… ( OID: #componentOID_1(attOID), Name: name, AggrOID: #aggregationOID_1(absOID), IsNullable: isNullable, IsKey: isIdent, Type : type ) SM_AttributeOfAbstract( OID: attOID, Name: name, AbstractOID: absOID, IsIdent: isIdent, IsNullable: isNullable, Type : type ) ; Skolem functions –are functions –are injective –have disjoint ranges the first function "generates" a new value the second "reuses" the value generated by the first rule

25 P. Atzeni15 marzo 200725 A component of the aggregation for each attribute of abstract" SM-Abstract OIDSchemaName 3011Employees 3021Departments ……… Employees EmpNo Name 11 Departments1002 Employees1001 … 3021002 …… 1001 SM-AggregationOfLexicals SchemaNameOID SM-aggregationOID_1_SK absOIDOID 301 SM_ComponentOfAggregation… ( OID: #componentOID_1(attOID), Name: name, AggrOID: #aggregationOID_1(absOID), IsNullable: isNullable, IsKey: isIdent, Type : type ) SM_AttributeOfAbstract( OID: attOID, Name: name, AbstractOID: absOID, IsIdent: isIdent, IsNullable: isNullable, Type : type ) ; SM-componentOID_1_SK absOIDOID Employees EmpNoName SM-AttributeOfAbstract OIDSchemaNameisIdentisNullableTypeAbstrOID 4011EmpNoTFInt301 4021NameFFText301 ………………… SM-ComponentOfAggregationOfLexicals SchemaTypeAggrOIDisNullableisIdentNameOID Text1001FFName111004 1001IntFTEmpNo11 1003 401 1004402 1003


Scaricare ppt "Complementi di basi di dati Progetti ModelGen - MIDST P. Atzeni, P. Cappellari, G. Gianforme 15 marzo 2007."

Presentazioni simili


Annunci Google