A Hierarchically Typed Relation Algebra Patrick Roocks Institut für Informatik, Universität Augsburg September 17, 2012
Introduction Basics The problem Multitypes Conclusion Motivation Motivation We have introduced a typed relational algebra to model: ▸ Tuples of a databases ▸ There the types represent the attributes (database columns) ▸ Relations between database tuples 2 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Motivation Motivation We have introduced a typed relational algebra to model: ▸ Tuples of a databases ▸ There the types represent the attributes (database columns) ▸ Relations between database tuples Additionally we introduced: ▸ A join algebra : Differently typed elements can be “glued together” ▸ This is embedded in a semiring with 1 and ⊺ 2 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Motivation Motivation We have introduced a typed relational algebra to model: ▸ Tuples of a databases ▸ There the types represent the attributes (database columns) ▸ Relations between database tuples Additionally we introduced: ▸ A join algebra : Differently typed elements can be “glued together” ▸ This is embedded in a semiring with 1 and ⊺ Application: ▸ Preferences in databases � → See talk tomorrow 2 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Motivation Outline Problems: ▸ Arbitrary unions are not typable with our typing mechanism ▸ 1 and ⊺ are also not typable ▸ This is a lack of uniformity in our algebra Our idea: ▸ Introducing an new typing concept covering arbitrary unions 3 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Motivation Outline Problems: ▸ Arbitrary unions are not typable with our typing mechanism ▸ 1 and ⊺ are also not typable ▸ This is a lack of uniformity in our algebra Our idea: ▸ Introducing an new typing concept covering arbitrary unions The talk is structured as follows: 1 Basics (Typing, Join-Algebra) 2 Sketch of the problem 3 Definition of the new typing mechanism 4 Some properties 3 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed tuples ▸ Database tuples consist of values according to their attributes ▸ We introduce types of relations according to their attribute names 4 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed tuples ▸ Database tuples consist of values according to their attributes ▸ We introduce types of relations according to their attribute names We use: ▸ A : set of attribute names (e.g. set of column names) ▸ D A for all A ∈ A : The type domain of the attribute, e.g. R , N , strings,... ( int, float, varchar,... ) 4 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed tuples Definition (Typed Tuples, (1/2) ) ▸ A type T is a subset T ⊆ A . ▸ An attribute A ∈ A also denotes the type { A } ▸ A T-tuple is a mapping t ∶ T → ⋃ D A where ∀ A ∈ T ∶ t ( A ) ∈ D A A ∈A ▸ The type domain D T for a type T is the set of all T -tuples, i.e. D T = ∏ D A A ∈ T 5 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed Tuples Definition (Typed Tuples, (2/2) ) U = df ⋃ ▸ The greatest type domain is the universe : D T T ⊆A ▸ Abbreviations: t ∶∶ T ⇔ df t ∈ D T , M ∶∶ T ⇔ df M ⊆ D T 6 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed Tuples Definition (Typed Tuples, (2/2) ) U = df ⋃ ▸ The greatest type domain is the universe : D T T ⊆A ▸ Abbreviations: t ∶∶ T ⇔ df t ∈ D T , M ∶∶ T ⇔ df M ⊆ D T Unions of types and differently typed tuples can be expressed by joins: Definition (Join) We define the join of types T 1 , T 2 and sets of tuples M i ∶∶ T i ( i = 1 , 2 ) T 1 ⋈ T 2 = df T 1 ∪ T 2 . M 1 ⋈ M 2 = df { t ∶∶ T 1 ⋈ T 2 ∣ t ∣ T i ∈ M i , i = 1 , 2 } 6 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations The join operator – an example Example Assume a database of cars with attributes: ID, model, power Consider the sets M 1 = {{ ID ↦ 1 , model ↦ ’BMW’ } , { ID ↦ 3 , model ↦ ’Mercedes’ }} M 2 = {{ ID ↦ 2 , power ↦ 230 } , { ID ↦ 3 , power ↦ 315 }} . The sets are typed as follows: M 1 ∶∶ ID ⋈ model , M 2 ∶∶ ID ⋈ power 7 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations The join operator – an example Example Assume a database of cars with attributes: ID, model, power Consider the sets M 1 = {{ ID ↦ 1 , model ↦ ’BMW’ } , { ID ↦ 3 , model ↦ ’Mercedes’ }} M 2 = {{ ID ↦ 2 , power ↦ 230 } , { ID ↦ 3 , power ↦ 315 }} . The sets are typed as follows: M 1 ∶∶ ID ⋈ model , M 2 ∶∶ ID ⋈ power The join M 1 ⋈ M 2 ∶∶ ID ⋈ model ⋈ power combines tuples with the same ID, because ( ID ⋈ model ) ∩ ( ID ⋈ power ) = ID M 1 ⋈ M 2 = {{ ID ↦ 3 , model ↦ ’Mercedes’ , power ↦ 315 }} 7 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Type assertions for elements and tests Algebraically: a ∶∶ T 2 ⇔ df a = 1 T ⋅ a ⋅ 1 T ⇔ df p ≤ 1 T p ∶∶ T 8 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Type assertions for elements and tests Algebraically: a ∶∶ T 2 ⇔ df a = 1 T ⋅ a ⋅ 1 T ⇔ df p ≤ 1 T p ∶∶ T In the concrete relational instances: ⇔ a ⊆ D T × D T a ∶∶ T 2 ⇔ p ⊆ D T p ∶∶ T 8 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Type assertions for elements and tests Algebraically: a ∶∶ T 2 ⇔ df a = 1 T ⋅ a ⋅ 1 T ⇔ df p ≤ 1 T p ∶∶ T In the concrete relational instances: ⇔ a ⊆ D T × D T a ∶∶ T 2 ⇔ p ⊆ D T p ∶∶ T Note that subidentities can be represented as sets: {( x , x ) ∣ x ∈ M } ↦ M for M ⊆ D T 8 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed relations and their join Definition (Typed homogeneous binary relations) For a type T we define: ( t 1 , t 2 ) ∶∶ T 2 ⇔ df R ∶∶ T 2 ⇔ df t i ∈ D T , R ⊆ D T × D T 9 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed relations and their join Definition (Typed homogeneous binary relations) For a type T we define: ( t 1 , t 2 ) ∶∶ T 2 ⇔ df R ∶∶ T 2 ⇔ df t i ∈ D T , R ⊆ D T × D T Special relations: T = df D T × D T ▸ The full relation ⊺ ▸ The identity 1 T = df {( x , x ) ∣ x ∶∶ T } ▸ The empty relation 0 T = df ∅ 9 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion Types and Tuples Typed relations Typed relations and their join Definition (Typed homogeneous binary relations) For a type T we define: ( t 1 , t 2 ) ∶∶ T 2 ⇔ df R ∶∶ T 2 ⇔ df t i ∈ D T , R ⊆ D T × D T Special relations: T = df D T × D T ▸ The full relation ⊺ ▸ The identity 1 T = df {( x , x ) ∣ x ∶∶ T } ▸ The empty relation 0 T = df ∅ Definition (Join of relations / Generalised Cartesian Product) For R i ∶∶ T 2 i ( i = 1 , 2 ) we define R 1 ⋈ R 2 ∶∶ ( T 1 ⋈ T 2 ) 2 t ( R 1 ⋈ R 2 ) u ⇔ df t ∣ T 1 R 1 u ∣ T 1 ∧ t ∣ T 2 R 2 u ∣ T 2 . 9 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion The problem ▸ Assume attributes A , B and tests p A ∶∶ { A } and p B ∶∶ { B } ▸ Consider the union p A + p B ▸ p A + p B ∶∶ { A , B } does not hold ▸ We have { A } ∪ { B } = { A } ⋈ { B } , but p A + p B is a union, not a join! 10 Patrick Roocks — A Hierarchically Typed Relation Algebra
Introduction Basics The problem Multitypes Conclusion The problem ▸ Assume attributes A , B and tests p A ∶∶ { A } and p B ∶∶ { B } ▸ Consider the union p A + p B ▸ p A + p B ∶∶ { A , B } does not hold ▸ We have { A } ∪ { B } = { A } ⋈ { B } , but p A + p B is a union, not a join! Consider the subsumption order x ≤ y = df x + y = y ▸ Consider the following inequation: p A ≤ p A + p B ≤ 1 ≤ ⊺ ▸ This is valid due to the definition of the subsumption order ▸ ( p A + p B ) , 1 and ⊺ are all not typable with “ ∶∶ ” 10 Patrick Roocks — A Hierarchically Typed Relation Algebra
Recommend
More recommend