45
THE HIERARCHICAL DATA MODEL SECTION 9 Fundamentals

THE HIERARCHICAL DATA MODEL SECTION 9

  • Upload
    tilly

  • View
    18

  • Download
    1

Embed Size (px)

DESCRIPTION

THE HIERARCHICAL DATA MODEL SECTION 9. Fundamentals. Introduction. Relational model Grounded in mathematics. Network model Evolved from effort to establish standards Hierarchical Evolved?. Some Hierarchical Systems. IMS. Most widely used Other Hierarchical Systems. - PowerPoint PPT Presentation

Citation preview

Page 1: THE HIERARCHICAL DATA MODEL SECTION 9

THE HIERARCHICAL DATA MODEL

SECTION 9

Fundamentals

Page 2: THE HIERARCHICAL DATA MODEL SECTION 9

Introduction

• Relational model– Grounded in mathematics

• Network model– Evolved from effort to establish standards

• Hierarchical– Evolved?

Page 3: THE HIERARCHICAL DATA MODEL SECTION 9

Some Hierarchical Systems

• Most widely used

• Other Hierarchical Systems

• IMS

Page 4: THE HIERARCHICAL DATA MODEL SECTION 9

• Developed in early 1960s

• The reason?

• Still remains an actively used DB

Page 5: THE HIERARCHICAL DATA MODEL SECTION 9

Basic Concepts

• Special case of the network model

• Parent

• Child

Page 6: THE HIERARCHICAL DATA MODEL SECTION 9

• Tree

• Hierarchical data model

• Segment types

• Parent-child relationship type

Page 7: THE HIERARCHICAL DATA MODEL SECTION 9

A conceptual model

RETIREMENTPLAN

EMPLOYEE

HAS-EMPLOYEE

PROVIDED-FOR

1

M M

1

DEPARTMENT

Page 8: THE HIERARCHICAL DATA MODEL SECTION 9

A network data model

DEPARTMENTRETIREMENT

PLAN

EMPLOYEE

DEPARTMENT/

EMPLOYEE SET

RETIREMNT PLAN/

EMPLOYEE SET

Page 9: THE HIERARCHICAL DATA MODEL SECTION 9

A hierarchical data model

DEPARTMENTRETIREMENT

PLAN

EMPLOYEE

DEPARTMENT/

EMPLOYEE PCR

RETIREMNT PLAN/

EMPLOYEE PCR

EMPLOYEE

Page 10: THE HIERARCHICAL DATA MODEL SECTION 9

Tree Structure Conventions

2. Every segment a child

3. A parent can have many children

4. A child can only have one parent

1. Root segment

Page 11: THE HIERARCHICAL DATA MODEL SECTION 9

6. Ancestors and dependent segments

7. Root of a sub-tree

5. A leaf segment

Page 12: THE HIERARCHICAL DATA MODEL SECTION 9

Hierarchical arrangement of segment types

DEPTNAME MANAGER

EMPNAME YRS-SVC

PROJNAME DIVISIONSKILLCODE SKILLNAME

DEPARTMENT

EMPLOYEE

SKILL ASSIGNEDTO

Segment type

Page 13: THE HIERARCHICAL DATA MODEL SECTION 9

Hierarchical occurrence tree

Accounting BlackMarketing Smith

DEPTNAME MANAGER

Engineering Cook

Bond 7

EMPNAME YRS-SVC

DEPARTMENT

EMPLOYEE

Mills 12Hill 5 Carter 3 Blake 6 Case 7 West 6

Programmer2

SKILLCODE

SKILL

SKILLNAME

Analyst5 Proj.A 3 Cost Acct.3 Engineer5 Proj.B 6

PROJNAME DIV

ASSIGNEDTO

Page 14: THE HIERARCHICAL DATA MODEL SECTION 9

Preorder Traversal Method

2. At any point, after recording a segment, record the leftmost child segment of the segment just recorded. If the segment has no child segment, move back up the tree one level and record the leftmost unrecorded child segment of the segment at that level. Continue until all segments are accounted for.

1. Begin at the root of the tree and record the root segment in a file

Page 15: THE HIERARCHICAL DATA MODEL SECTION 9

A

B C D

FE G H I J K

D

E E E

S S SA A A A

Segment type indicator

Department Segment Type

Employee Segment Type

Skill and AssignedTo Segment Type

Level 1

Level 2

Level 3

Illustration of Preorder Traversal

Page 16: THE HIERARCHICAL DATA MODEL SECTION 9

• The following file will be generatedIteration Segment Segment-Type Indicator

1 A D

2 B E

3 E S

4 F A

5 G A

6 C E

7 H S

8 I A

9 D E

10 J S

11 K A

Page 17: THE HIERARCHICAL DATA MODEL SECTION 9

The Models Relationship to Conceptual Modeling• Transforming a conceptual model to a

hierarchical data structure

• One - Many Relationships

Page 18: THE HIERARCHICAL DATA MODEL SECTION 9

Transforming One-Many Relationships

Very simple

DEPARTMENT EMPLOYEEHAS-

EMPLOYEE1 N

DEPTNAME LOCATION MANAGER EMPNAME ADDRESS YRS-SVC

DEPTNAME LOCATION MANAGERDEPARTMENT

EMPNAME ADDRESS YRS-SVCEMPLOYEE

Page 19: THE HIERARCHICAL DATA MODEL SECTION 9

• Redundancy problems

DEPARTMENTRETIREMENT

PLAN

HAS-EMPLOYEE

1

N

DEPTNAME LOCATION MANAGER TYPE ENROLL-DATE AMOUNT

PROVIDED-FOR

EMPLOYEE

YRS-SVCADDRESSEMPNAME

1

N

• What is the problem?

Page 20: THE HIERARCHICAL DATA MODEL SECTION 9

DEPTNAME LOCATION MANAGER

DEPARTMENT

EMPNAME ADDRESS YRS-SVC

EMPLOYEE

TYPEENROLL-

DATEAMOUNT

RETIREMENT-PLAN

EMPNAME ADDRESS YRS-SVC

EMPLOYEE

Page 21: THE HIERARCHICAL DATA MODEL SECTION 9

1. For each entity set E in a conceptual model, create a segment type S in the hierarchical model. All attributes of E are represented as fields of S.

2. For one-many relationships between two entity sets, create corresponding tree structure diagrams, making each entity a segment and making the one-many relationship a parent-child relationship. The segment on the “many” side becomes the child, and the segment on the one side becomes the parent.

• The following rules:

Page 22: THE HIERARCHICAL DATA MODEL SECTION 9

Transforming Many-Many Relationships

A more complex situation

PRODUCT

SUPPLIER

IS-SUPPLIED-

BY

N

ID DESCRIPTION PRICE

NAME

LOCATION

M

Page 23: THE HIERARCHICAL DATA MODEL SECTION 9

ID DESCRIPTION PRICEPRODUCT

NAME LOCATIONMANUFACTURER

ID DESCRIPTION PRICEPRODUCT

NAME LOCATIONMANUFACTURER

3. For entity sets, E1 and E2, that have a many-many binary relationship, and from which segments S1 and S2 have been identified, construct two different one-many PCRs: S1 to S2, and S2 to S1.

Page 24: THE HIERARCHICAL DATA MODEL SECTION 9

Many-Many Relationship with an Attribute

PRODUCT

SUPPLIER

IS-SUPPLIED-

BY

N

ID DESCRIPTION PRICE

NAME

LOCATION

M

QUANTITY

Page 25: THE HIERARCHICAL DATA MODEL SECTION 9

4. If a binary many-many relationship has attribute data, create a new intersection segment I, which contains that data.

ID DESCRIPTION PRICEPRODUCT

NAME LOCATIONMANUFACTURER

QUANTITYQUANTITY

ID DESCRIPTION PRICEPRODUCT

NAME LOCATIONMANUFACTURER

QUANTITYQUANTITY

Page 26: THE HIERARCHICAL DATA MODEL SECTION 9

The IMS Architecture

• Hierarchical data model has no standard

• Must be hierarchically oriented

• Limit on segment types

Page 27: THE HIERARCHICAL DATA MODEL SECTION 9

• Database Description (DBD)

• Program Specification Block (PSB)

• Program Communication Block

• DL/1

Page 28: THE HIERARCHICAL DATA MODEL SECTION 9

Defining the Physical Database – The DBD

• An example – four segment types– DEPARTMENT

– EMPLOYEE

– SKILL

– ASSIGNEDTO

• The DBD is analogous to the network schema

Page 29: THE HIERARCHICAL DATA MODEL SECTION 9

1 DBD NAME = DEPTPERS, ACCESS = HISAM

2 SEGM NAME = DEPARTMENT, PARENT = 0, BYTES = 20

3 FIELD NAME = (DEPTNAME,SEQ,U), BYTES = 10, START = 1, TYPE = C

4 FIELD NAME = MANAGER, BYTES = 10, START = 11, TYPE = C

5 SEGM NAME = EMPLOYEE, PARENT = DEPARTMENT, BYTES = 22

6 FIELD NAME = (EMPNAME,SEQ), BYTES = 20, START = 1, TYPE = C

7 FIELD NAME = YRS-SVC, BYTES = 2, START = 21, TYPE = P

8 SEGM NAME = SKILL, PARENT = EMPLOYEE, BYTES = 17

9 FIELD NAME = (SKILLCODE,SEQ), BYTES = 2, START = 1, TYPE = P

10 FIELD NAME = SKILLNAME, BYTES = 15, START = 3, TYPE = C

11 SEGM NAME = ASSIGNEDTO, PARENT = EMPLOYEE, BYTES = 4

12 FIELD NAME = (PROJNI,SEQ), BYTES = 2, START = 1, TYPE = P

13 FIELD NAME = DIVISION, BYTES = 2, START = 3, TYPE = C

14 DBGEN

Page 30: THE HIERARCHICAL DATA MODEL SECTION 9

Defining the Logical Database – The PSB

• The PCB

• Sensitive segments

• Analogous to the network subschema

Page 31: THE HIERARCHICAL DATA MODEL SECTION 9

• PROCOPTG = GET

I = INSERT

R = REPLACE

D = DELETE

A = ALL

1 PCB TYPE = DB, DBNAME = DEPTERS, PROCOPT = A, KEYLEN = 18

2 SENSEG NAME = DEPARTMENT, PARENT = 0

3 SENSEG NAME = DEPTNAME, START = 1

4 SENSEG NAME = EMPLOYEE, PARENT = DEPARTMENT

5 SENFLD NAME = EMPNAME, START = 1

Page 32: THE HIERARCHICAL DATA MODEL SECTION 9

IMS Access Methods

• HISAM

• HDAM

• HIDAM

• HSAM

Page 33: THE HIERARCHICAL DATA MODEL SECTION 9

DEPTNAME

Smith

MANAGER

Marketing

Bond

EMPNAME

7

YRS-SVC

Hill

EMPNAME

5

YRS-SVC

Programmer2

SKILLCODE SKILLNAME

SystemsAnalyst

5

SKILLCODE SKILLNAME

Sales10

SKILLCODE SKILLNAME

Tree Occurrence Example

Page 34: THE HIERARCHICAL DATA MODEL SECTION 9

Hierarchical Pointers

DEPTNAME

Smith

MANAGER

Marketing*

Bond

EMPNAME

7

YRS-SVC

*

Programmer2

SKILLCODE SKILLNAME

*SystemsAnalyst

5*

Hill 5*

Sales10o

Page 35: THE HIERARCHICAL DATA MODEL SECTION 9

Child and Twin Pointers

DEPTNAME

Smith

MANAGER

Marketing**

(TwinPointer)

YRS-SVC

Bond

EMPNAME

7**

(ChildPointer)

SKILLNAME

Programmer2

SKILLCODE

*o

Hill 5o*

SystemsAnalyst

5oo Sales10oo

Page 36: THE HIERARCHICAL DATA MODEL SECTION 9

The IMS Data Manipulation Language

• Program Work Area

– Segment templates

– Currency templates

• The language?

Page 37: THE HIERARCHICAL DATA MODEL SECTION 9

GET UNIQUE (GU)

GET NEXT (GN)

GET NEXT WITHIN PARENT (GNP)

<hold options> GHU, GHN, GHNP

INSERT (ISRT)

REPLACE (REPL)

DELETE (DLET)

Retrieve the first segment that satisfies a given condition

Retrieve the next segment

Retrieves the next segment, but only within the current parent

Lock the database for GU, GN, GNP

Add a new segment to the database

Modify the value of a segment field

Delete a segment

DL/1

• Data Language 1• Commonly used commands

Command <segment name> <WHERE qualification>

Page 38: THE HIERARCHICAL DATA MODEL SECTION 9

1. A Simple Segment Retrieval

GU DEPARTMENT (DEPTNAME = ‘Marketing’)

• Get Unique (GU)

2. Retrieval of a Dependent Segment

GU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE? (EMPNAME = ‘Steve Smith’)

Page 39: THE HIERARCHICAL DATA MODEL SECTION 9

3. Retrieval of dependent Segment When Parent is Not Known

GU DEPARTMENT

EMPLOYEE (EMPNAME = ‘Steve Smith’)

4. Retrieval of a Set of Segments

GU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE

GN EMPLOYEE

• Get Next (GN)

Page 40: THE HIERARCHICAL DATA MODEL SECTION 9

5. Retrieving All Segments of a Particular Type

GU DEPARTMENT

EMPLOYEE

MORE GN EMPLOYEE

GOTO MORE

6. Retrieving Segments for Just One ParentGU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE

GNP EMPLOYEE

• Get Next Within Parent (GNP)

Page 41: THE HIERARCHICAL DATA MODEL SECTION 9

7. Retrieving Segments for Just One Parent

GU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE (EMPNAME = ‘Steve Smith’)

SKILLS

NEXT GNP SKILLS

GOTO NEXT

• GET HOLD UNIQUE• GET HOLD NEXT• GET HOLD NEXT WITHIN PARENT

• Get Hold

Page 42: THE HIERARCHICAL DATA MODEL SECTION 9

• Replace (REPL)

8. Modifying Segment Field Values

GHU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE (EMPNAME = ‘Irving Valtz’)

MOVE 55000 TO SALARY

REPL

Page 43: THE HIERARCHICAL DATA MODEL SECTION 9

• Delete (DLET)

9. Deleting a Segment

GHU DEPARTMENT (DEPTNAME = ‘Marketing’)

EMPLOYEE (EMPNAME = ‘Irving Valtz’)

DLET

Page 44: THE HIERARCHICAL DATA MODEL SECTION 9

• Insert (INSRT)

10. Adding a Segment

MOVE 598 TO SKILLCODE

MOVE ‘ENGINEERING DRAFTSMAN’ TO SKILLNAME

MOVE 0 TO YRS-EXPERIENCE

INSRT DEPARTMENT (DEPTNAME = ‘Engineering’)

EMPLOYEE (EMPNAME = ‘Bob Lee’)

SKILL

Page 45: THE HIERARCHICAL DATA MODEL SECTION 9

1. Data representation

Hierarchical Data Model Evaluation

2. Data manipulation language