hierarchical data model - university of cyprushierarchical data model history: • the oldest of the...

21
HIERARCHICAL DATA MODEL

Upload: others

Post on 14-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

HIERARCHICAL DATA

MODEL

Page 2: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Hierarchical Data ModelHistory:• The oldest of the three models, dating from 1960’s• “Ad Hoc” solution to immediate needs of real applications• The oldest hierarchical database system, IBM’s IMS, was

developed to organize and store information needed by the space program for the Apollo Landing Project.

• The first hierarchical DBMS is “IMS” and it was released in 1968.• “IMS” is still the dominant DBMS. The relational DB2 is rapidly

gaining ground.• Process data efficiently.• It uses a structure familiar to program.• Provides predictable performance since all paths are known.• However not as flexible or as easy to understand as relational

system.

Page 3: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Hierarchical Data ModelHierarchy

1. Networks that are forests(Collection Trees)2. All links are from Parent to Child.

ONE-TO-MANY relation.3. In the previous Data Models Relational & Networks

relationships could be followed easily by operation of the model, Joins and Link following.

Can not follow links from child to parent.4. Networks can be converted to hierarchies by Splitting.5. Hierarchies are easy to store.

- Preserve hierarchy through pointers- Using Preorder Traversal to get a flat representation of the tree.

Page 4: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs
Page 5: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

SIMPLY EXAMPLE

• Lets assume the following relationships– Faculty-Class ONE-MANY– Class-Student ONE-MANY (Instead of n-n)

Page 6: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Simplify Example• Instate of “Database Record”

• Possible Storage schema:- Preorder Traversal to get flat representation of the above instance.

Page 7: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Operations in the Hierarchical Model• Top Down queries are easy to ask.“Find all courses taught by Peter in CS”

• Bottom up queries not that easy.“Find the class in room 63”

• Navigation between different occurrence of the record difficult.

“Find all courses enrolled by ‘Dave’ “

Page 8: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Problems 1. Repeated data.2. Potential inconsistencies.3. Navigation between different occurrences of the

same record difficult.4. Bottom Up queries inefficient.

Solution1. Different structure for our tree.2. Virtual record types.

Page 9: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Example• Using the “Simplify Example” if the query type:

“Find information about student Y”• Is more frequent than:

“Find information about all classes taught by Prof. X”• Then change structure:

Page 10: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Most common way “Virtual Records”

Two directional navigation is possible.(For one-many Rel.)

Page 11: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Representing many-many Relationships

• The “Virtual Record” feature provides us with great flexibility.

Page 12: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs
Page 13: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Alternative Designs• Combined record types

- Fields of records can hold pointers(Virtual Fields).

- We are able to record course grade.(as in the original design)

Query:“Find all the grades issued in CS101”

Page 14: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

• If too inefficient several other schemes can be used, i.e.

Query:“Find all the grades issued in CS101”

Page 15: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Object Oriented Model• Features:

1. Object Identity:

2. Complex Objects:

3. Type Hierarchy:

The elements with which they deal are objects(entities) with unique addresses.

Higher level objects composed by lower level objects using record formation and set formation.(This is a basic set of constructors)

Types can have subtypes with special properties. The notion of Class-Subclass.

Page 16: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Object Types:1. Elementary types: integer, real, char, string, ...

2. If T is an object type then: SETOF(T) is an object type.

3. If T1, T2, …, Tk are objects types, then RECORDOF(T1, T2, …, Tk) is an object type.

Thus,Records of SETS, sets of RECORDS, etc are possible.

- An object of type SETOF(T) is a collection of objects of type T.

Page 17: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Example:

• A relation is an object type:- Set of records constraining primitive values- An actual table is an instance of the object type relation.

Page 18: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

Department

Faculty

Student

Course

Page 19: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

• Easy to get from DEPARTMENT to COURSES but not vice versa.– Can be achieved by defining new object types.

• Declare:

Page 20: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

TYPE HIERARCHY• Subtypes

– Structural: more attributes in the subtype.Example:

– Behavioral: some operations can be applied only to the subtype.Example:– The method “rank” or “getDegree” can be only applied to the

subtype FACULTY.

Page 21: Hierarchical Data Model - University of CyprusHierarchical Data Model History: • The oldest of the three models, dating from 1960’s • “Ad Hoc” solution to immediate needs

OBJECT DDL

• Object Behavior:– Methods– Abstract Data Type Operations

• Very Limited Extensions of the Underlying host Language (C++, Objective-C, Smalltalk)

– Add Data Persistence.• Easy Direct Manipulation: Browsing.• Need for a Higher-Level Language e.g. like SQL

(Relation Algebra).