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.
THE HIERARCHICAL DATA MODELSECTION 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
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 RETIREMENT PLAN DEPARTMENT EMPLOYEE 1 1 HAS- EMPLOYEE PROVIDED- FOR M M
A network data model DEPARTMENT RETIREMENT PLAN DEPARTMENT/ EMPLOYEE SET RETIREMNT PLAN/ EMPLOYEE SET EMPLOYEE
A hierarchical data model DEPARTMENT RETIREMENT PLAN DEPARTMENT/ EMPLOYEE PCR RETIREMNT PLAN/ EMPLOYEE PCR EMPLOYEE EMPLOYEE
Tree Structure Conventions • Root segment • Every segment a child • A parent can have many children • A child can only have one parent
A leaf segment • Ancestors and dependent segments • Root of a sub-tree
Hierarchical arrangement of segment types Segment type DEPTNAME EMPNAME PROJNAME SKILLCODE MANAGER YRS-SVC DIVISION SKILLNAME DEPARTMENT EMPLOYEE SKILL ASSIGNEDTO
Hierarchical occurrence tree DEPARTMENT DEPTNAME MANAGER Marketing Smith EMPLOYEE EMPNAME YRS-SVC Carter Blake West Mills Hill Bond Case 12 7 6 5 6 7 3 Engineering Accounting Cook Black Proj.B Proj.A 6 3 SKILL ASSIGNEDTO SKILLCODE SKILLNAME PROJNAME DIV 5 2 3 5 Cost Acct. Engineer Programmer Analyst
Preorder Traversal Method • Begin at the root of the tree and record the root segment in a file • 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.
Segment type indicator D A Department Segment Type Level 1 E E E B C D Employee Segment Type Level 2 S A S A A S A E F G H I J K Level 3 Skill and AssignedTo Segment Type Illustration of Preorder Traversal
The Models Relationship to Conceptual Modeling • Transforming a conceptual model to a hierarchical data structure • One - Many Relationships
Transforming One-Many Relationships DEPTNAME LOCATION MANAGER EMPNAME ADDRESS YRS-SVC HAS- EMPLOYEE DEPARTMENT EMPLOYEE 1 N DEPARTMENT EMPLOYEE DEPTNAME EMPNAME LOCATION ADDRESS YRS-SVC MANAGER Very simple
DEPTNAME LOCATION MANAGER TYPE ENROLL-DATE AMOUNT DEPARTMENT RETIREMENT PLAN 1 1 HAS- EMPLOYEE PROVIDED- FOR N N EMPLOYEE EMPNAME ADDRESS YRS-SVC • Redundancy problems • What is the problem?
DEPARTMENT RETIREMENT-PLAN EMPLOYEE EMPLOYEE DEPTNAME EMPNAME TYPE EMPNAME LOCATION ADDRESS ENROLL- DATE ADDRESS MANAGER YRS-SVC AMOUNT YRS-SVC
The following rules: • 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. • 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.
Transforming Many-Many Relationships ID DESCRIPTION PRICE PRODUCT N IS- SUPPLIED- BY M NAME SUPPLIER LOCATION A more complex situation
ID DESCRIPTION PRICE PRODUCT NAME LOCATION MANUFACTURER ID DESCRIPTION PRICE PRODUCT NAME LOCATION MANUFACTURER • 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 ID DESCRIPTION PRICE PRODUCT N QUANTITY IS- SUPPLIED- BY M NAME SUPPLIER LOCATION
ID DESCRIPTION PRICE ID DESCRIPTION PRICE PRODUCT PRODUCT QUANTITY QUANTITY QUANTITY QUANTITY NAME LOCATION NAME LOCATION MANUFACTURER MANUFACTURER • If a binary many-many relationship has attribute data, create a new intersection segment I, which contains that data.
The IMS Architecture • Hierarchical data model has no standard • Must be hierarchically oriented • Limit on segment types
DL/1 • Database Description (DBD) • Program Specification Block (PSB) • Program Communication Block
Defining the Physical Database – The DBD • The DBD is analogous to the network schema • An example – four segment types • DEPARTMENT • EMPLOYEE • SKILL • ASSIGNEDTO
DBD NAME = DEPTPERS, ACCESS = HISAM • SEGM NAME = DEPARTMENT, PARENT = 0, BYTES = 20 • FIELD NAME = (DEPTNAME,SEQ,U), BYTES = 10, START = 1, TYPE = C • FIELD NAME = MANAGER, BYTES = 10, START = 11, TYPE = C • SEGM NAME = EMPLOYEE, PARENT = DEPARTMENT, BYTES = 22 • FIELD NAME = (EMPNAME,SEQ), BYTES = 20, START = 1, TYPE = C • FIELD NAME = YRS-SVC, BYTES = 2, START = 21, TYPE = P • SEGM NAME = SKILL, PARENT = EMPLOYEE, BYTES = 17 • FIELD NAME = (SKILLCODE,SEQ), BYTES = 2, START = 1, TYPE = P • FIELD NAME = SKILLNAME, BYTES = 15, START = 3, TYPE = C • SEGM NAME = ASSIGNEDTO, PARENT = EMPLOYEE, BYTES = 4 • FIELD NAME = (PROJNI,SEQ), BYTES = 2, START = 1, TYPE = P • FIELD NAME = DIVISION, BYTES = 2, START = 3, TYPE = C • DBGEN
Defining the Logical Database – The PSB • Analogous to the network subschema • The PCB • Sensitive segments
PCB TYPE = DB, DBNAME = DEPTERS, PROCOPT = A, KEYLEN = 18 • SENSEG NAME = DEPARTMENT, PARENT = 0 • SENSEG NAME = DEPTNAME, START = 1 • SENSEG NAME = EMPLOYEE, PARENT = DEPARTMENT • SENFLD NAME = EMPNAME, START = 1 • PROCOPT G = GET I = INSERT R = REPLACE D = DELETE A = ALL
IMS Access Methods • HSAM • HISAM • HDAM • HIDAM
SKILLCODE SKILLCODE SKILLCODE SKILLNAME SKILLNAME SKILLNAME 10 5 2 Programmer Sales Systems Analyst DEPTNAME MANAGER Marketing Smith EMPNAME EMPNAME YRS-SVC YRS-SVC Hill Bond 5 7 Tree Occurrence Example
DEPTNAME MANAGER * Marketing Smith EMPNAME YRS-SVC * Bond 7 * Hill 5 SKILLCODE SKILLNAME * 2 Programmer * 5 Systems Analyst o 10 Sales Hierarchical Pointers
DEPTNAME MANAGER * * Marketing Smith (Child Pointer) (Twin Pointer) EMPNAME YRS-SVC * * Bond 7 * o Hill 5 SKILLCODE SKILLNAME o * 2 Programmer o o 5 Systems Analyst o o 10 Sales Child and Twin Pointers
The IMS Data Manipulation Language • The language? • Program Work Area • Segment templates • Currency templates
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>
Get Unique (GU) • A Simple Segment Retrieval GU DEPARTMENT (DEPTNAME = ‘Marketing’) • Retrieval of a Dependent Segment GU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE? (EMPNAME = ‘Steve Smith’)
Retrieval of dependent Segment When Parent is Not Known GU DEPARTMENT EMPLOYEE (EMPNAME = ‘Steve Smith’) • Get Next (GN) • Retrieval of a Set of Segments GU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE GN EMPLOYEE
Retrieving All Segments of a Particular Type GU DEPARTMENT EMPLOYEE MORE GN EMPLOYEE GOTO MORE • Get Next Within Parent (GNP) • Retrieving Segments for Just One Parent GU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE GNP EMPLOYEE
Retrieving Segments for Just One Parent GU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE (EMPNAME = ‘Steve Smith’) SKILLS NEXT GNP SKILLS GOTO NEXT • Get Hold • GET HOLD UNIQUE • GET HOLD NEXT • GET HOLD NEXT WITHIN PARENT
Replace (REPL) • Modifying Segment Field Values GHU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE (EMPNAME = ‘Irving Valtz’) MOVE 55000 TO SALARY REPL
Delete (DLET) • Deleting a Segment GHU DEPARTMENT (DEPTNAME = ‘Marketing’) EMPLOYEE (EMPNAME = ‘Irving Valtz’) DLET
Insert (INSRT) • 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
Hierarchical Data Model Evaluation • Data representation • Data manipulation language