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
• Most widely used
• Other Hierarchical Systems
• IMS
• Developed in early 1960s
• The reason?
• Still remains an actively used DB
Basic Concepts
• Special case of the network model
• Parent
• Child
• Tree
• Hierarchical data model
• Segment types
• Parent-child relationship type
A conceptual model
RETIREMENTPLAN
EMPLOYEE
HAS-EMPLOYEE
PROVIDED-FOR
1
M M
1
DEPARTMENT
A network data model
DEPARTMENTRETIREMENT
PLAN
EMPLOYEE
DEPARTMENT/
EMPLOYEE SET
RETIREMNT PLAN/
EMPLOYEE SET
A hierarchical data model
DEPARTMENTRETIREMENT
PLAN
EMPLOYEE
DEPARTMENT/
EMPLOYEE PCR
RETIREMNT PLAN/
EMPLOYEE PCR
EMPLOYEE
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
6. Ancestors and dependent segments
7. Root of a sub-tree
5. A leaf segment
Hierarchical arrangement of segment types
DEPTNAME MANAGER
EMPNAME YRS-SVC
PROJNAME DIVISIONSKILLCODE SKILLNAME
DEPARTMENT
EMPLOYEE
SKILL ASSIGNEDTO
Segment type
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
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
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
• 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
The Models Relationship to Conceptual Modeling• Transforming a conceptual model to a
hierarchical data structure
• One - Many Relationships
Transforming One-Many Relationships
Very simple
DEPARTMENT EMPLOYEEHAS-
EMPLOYEE1 N
DEPTNAME LOCATION MANAGER EMPNAME ADDRESS YRS-SVC
DEPTNAME LOCATION MANAGERDEPARTMENT
EMPNAME ADDRESS YRS-SVCEMPLOYEE
• 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?
DEPTNAME LOCATION MANAGER
DEPARTMENT
EMPNAME ADDRESS YRS-SVC
EMPLOYEE
TYPEENROLL-
DATEAMOUNT
RETIREMENT-PLAN
EMPNAME ADDRESS YRS-SVC
EMPLOYEE
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:
Transforming Many-Many Relationships
A more complex situation
PRODUCT
SUPPLIER
IS-SUPPLIED-
BY
N
ID DESCRIPTION PRICE
NAME
LOCATION
M
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.
Many-Many Relationship with an Attribute
PRODUCT
SUPPLIER
IS-SUPPLIED-
BY
N
ID DESCRIPTION PRICE
NAME
LOCATION
M
QUANTITY
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
The IMS Architecture
• Hierarchical data model has no standard
• Must be hierarchically oriented
• Limit on segment types
• Database Description (DBD)
• Program Specification Block (PSB)
• Program Communication Block
• DL/1
Defining the Physical Database – The DBD
• An example – four segment types– DEPARTMENT
– EMPLOYEE
– SKILL
– ASSIGNEDTO
• The DBD is analogous to the network schema
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
Defining the Logical Database – The PSB
• The PCB
• Sensitive segments
• Analogous to the network subschema
• 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
IMS Access Methods
• HISAM
• HDAM
• HIDAM
• HSAM
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
Hierarchical Pointers
DEPTNAME
Smith
MANAGER
Marketing*
Bond
EMPNAME
7
YRS-SVC
*
Programmer2
SKILLCODE SKILLNAME
*SystemsAnalyst
5*
Hill 5*
Sales10o
Child and Twin Pointers
DEPTNAME
Smith
MANAGER
Marketing**
(TwinPointer)
YRS-SVC
Bond
EMPNAME
7**
(ChildPointer)
SKILLNAME
Programmer2
SKILLCODE
*o
Hill 5o*
SystemsAnalyst
5oo Sales10oo
The IMS Data Manipulation Language
• Program Work Area
– Segment templates
– Currency templates
• The language?
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>
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’)
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)
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)
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
• Replace (REPL)
8. Modifying Segment Field Values
GHU DEPARTMENT (DEPTNAME = ‘Marketing’)
EMPLOYEE (EMPNAME = ‘Irving Valtz’)
MOVE 55000 TO SALARY
REPL
• Delete (DLET)
9. Deleting a Segment
GHU DEPARTMENT (DEPTNAME = ‘Marketing’)
EMPLOYEE (EMPNAME = ‘Irving Valtz’)
DLET
• 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
1. Data representation
Hierarchical Data Model Evaluation
2. Data manipulation language
Top Related