Recursive Data Relationships
Oracle Tips by Burleson Consulting
The Data Warehouse Development Life Cycle
Oracle Data Warehouse Design
Dealing With Recursive Data Relationships
Clearly, we compound the problem of recursive relationships by
adding this additional construct--namely, a class hierarchy (see
Figure 4.12). Unfortunately, these types of
challenges are very common. While it is true that "parts are parts,"
the different parts have subtle variations, leading to different
data items depending on part type. For example, a food-related part
might have a shelf_life column, but that column does not
apply to a nonfood-related part. The class hierarchy design in
Oracle tables is covered later in this chapter.
Figure 4.12 A recursive many-to-many relationship with the
addition of an IS-A hierarchy.
With an understanding of the nature
of recursive relationships, the question becomes one of
implementation--What is the best way to represent a recursive
relationship in Oracle and navigate the structure?
The following Oracle table
definitions describe the tables for the part-component example:
CREATE table PART(
CREATE table COMPONENT (
Look closely at the COMPONENT
example. Both the Has_part and Is_a_part fields are
foreign keys for the part_nbr field in the PART table.
Therefore, the component table is all keyed except for the qty
field, which tells how many parts belong in an assembly. Look at the
following SQL code that is required to display the components in a
FROM PART, COMPONENET
SEE CODE DEPOT FOR FULL SCRIPT
This type of Oracle SQL query
requires joining the table against itself. Unfortunately, because
all items are of the same type (namely, PART), no real
substitute exists for this type of data relationship.
This is an excerpt from "High Performance
Data Warehousing", copyright 1997.
If you like Oracle tuning, you may enjoy the book
Oracle Tuning: The Definitive Reference , with over 900 pages of BC's favorite tuning
tips & scripts.
You can buy it directly from the publisher and save 30%, and get
instant access to the code depot of Oracle tuning scripts.