SlideShare a Scribd company logo
Oracle Materialized Views For
Hierarchical Data Storage And Retrieval.
Materialized Views Application

Materialized views is well known concept to any oracle pl/sql enthusiast. Lets look at a case
study where materialized views are used to achieve the desired result with the expected
performance.

Storage and Query of Hierarchical Data:

Any programmer would have invariably come across the problem of storage and retrieval of
data that share a hierarchy among themselves.

The most common would be storing location data as in Country>>State>>City. Lets assume for
this discussion that a record/node has only one parent. One way to store this data is to have
separate table structure for each level i.e. Country, state, city etc. However this method may not
be suitable for a rapidly changing system. Let’s say a new country gets added which has further
segregation like "Country>>State>>City>>County”. Hence to represent the data one has to add a
new table County to the data model in the current design to be able to store the data. Needless
to say that one also has to change the retrieval query joins to bring in the new data.

An approach to the above problem can be , the above data can be stored in a single table with
every record having a reference to its parent record. This approach of representing a tree is
commonly known Adjacency list as the parent-child are adjacent to each other.
Adjacency List For Location/Place




This structure takes care of the variable depth problem of the tree. Hence now
data of any depth can be stored without creating new tables to the data model.
Another example would be the reporting structure of an employee. A junior
employee may have a long chain of supervisors going up to the CEO, where as a
CEO may report to only one person.
The previous slide structure while adding flexibility does introduce some limitations, most
of which can be worked around but at the cost of performance.


While queries that involves immediate children, like finding the states in countries or cities
in State are very fast, things starts to get messy when one needs to find all the
descendants of a node. May be one can use CONNECT BY clause with
SYS_CONNECT_BY_PATH to achieve it. But that will need more computation and string
comparisons.


A more elegant approach would be to make use of Closure Tables to represent the tree. A
closure table stores, as records, pair of nodes that have an ancestor/descendant
relationship irrespective of the depth or level of the nodes in the tree.
Closure Table For Location/Place
Hence while adjacency list is more intuitive, closure table performs better for data retrieval
of course with some space usage overheads. Now to have the best of both worlds , one
may use the adjacency list for accepting data from the User Interface for OLTP systems or
by data uploads in DSS systems. Then a materialized view could be used to create the
Closure table over the adjacency list table. Every time data is loaded , the materialized
view can be refreshed to recreate the closure table. The closure table is used in the joins
with other tables in the queries.

More Related Content

PPTX
ADB introduction
PPT
Building a Spatial Database in PostgreSQL
DOCX
Data mining with ms access
PDF
Reduce Side Joins
PPTX
Ui path interview questions
PPTX
Tableau Interview Questions
PPTX
Join Algorithms in MapReduce
DOC
Uop dbm 502 week 6 big data paper
ADB introduction
Building a Spatial Database in PostgreSQL
Data mining with ms access
Reduce Side Joins
Ui path interview questions
Tableau Interview Questions
Join Algorithms in MapReduce
Uop dbm 502 week 6 big data paper

What's hot (19)

DOC
Uop dbm 502 week 6 big data paper
PDF
Big data analytics K.Kiruthika II-M.Sc.,Computer Science Bonsecours college f...
PPTX
Data integration
PPTX
Data Structures Using Object Oriented Programming
PPT
Aginity "Big Data" Research Lab
PPTX
Back to the future - Temporal Table in SQL Server 2016
PDF
The Portable Freeware Collection • View topic
PPTX
Big data analytics: Technology's bleeding edge
DOCX
Abstract.DOCX
PDF
Tableau And Data Visualization - Get Started
PPTX
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
PDF
Tableau file types
PPTX
Presentation1
PPTX
DMDW 7. Student Presentation - Pentaho Data Integration (Kettle)
PDF
Diplo cloud efficient and scalable management of rdf data in the cloud
DOCX
R programming analysis
PPTX
Hadoop MapReduce joins
PDF
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
DOCX
Annotating search results from web databases
Uop dbm 502 week 6 big data paper
Big data analytics K.Kiruthika II-M.Sc.,Computer Science Bonsecours college f...
Data integration
Data Structures Using Object Oriented Programming
Aginity "Big Data" Research Lab
Back to the future - Temporal Table in SQL Server 2016
The Portable Freeware Collection • View topic
Big data analytics: Technology's bleeding edge
Abstract.DOCX
Tableau And Data Visualization - Get Started
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
Tableau file types
Presentation1
DMDW 7. Student Presentation - Pentaho Data Integration (Kettle)
Diplo cloud efficient and scalable management of rdf data in the cloud
R programming analysis
Hadoop MapReduce joins
EVALUATING CASSANDRA, MONGO DB LIKE NOSQL DATASETS USING HADOOP STREAMING
Annotating search results from web databases
Ad

Viewers also liked (17)

PDF
Sql query tuning or query optimization
PPTX
Lect 08 materialized view
PPTX
Cloud architectural patterns and Microsoft Azure tools
PDF
PostgreSQL Materialized Views with Active Record
PDF
Synchronize Code and Documentation - An introduction to Cucumber and Java
PPTX
Emergent Process Design
PDF
12 Ways Secure Texting is Used in Healthcare
PDF
Metasite Business Solutions booklet
PPTX
Silos Are For Farmers, Not IT
PPTX
כנס מדבר יהודה לדורותיו 2005 2015 חלק שני
PPTX
Reading. Writing. Using. Online Copywriting
PDF
Into the Breach-Data Breach Statistics Infographic
PPTX
DMA - Art of Targeting and Personalization
PPTX
British Columbia - How to Compete and Win in 2016
PPSX
NextDocs Regulatory Document Management webinar 041211
PDF
Mobile & IoT in Field Service
PDF
Investing tips-to-grow-wealth
Sql query tuning or query optimization
Lect 08 materialized view
Cloud architectural patterns and Microsoft Azure tools
PostgreSQL Materialized Views with Active Record
Synchronize Code and Documentation - An introduction to Cucumber and Java
Emergent Process Design
12 Ways Secure Texting is Used in Healthcare
Metasite Business Solutions booklet
Silos Are For Farmers, Not IT
כנס מדבר יהודה לדורותיו 2005 2015 חלק שני
Reading. Writing. Using. Online Copywriting
Into the Breach-Data Breach Statistics Infographic
DMA - Art of Targeting and Personalization
British Columbia - How to Compete and Win in 2016
NextDocs Regulatory Document Management webinar 041211
Mobile & IoT in Field Service
Investing tips-to-grow-wealth
Ad

Similar to OracleMaterializedviews & Hierarchical Data (20)

ODP
How do You Graph
PDF
ITB - UNIT 3.pdf
PPT
Chapter 2 Database Systems Architectures
PPTX
Importance of data model
PPTX
Architecture of dbms
PDF
Dbms viva questions
PPTX
Improve data warehouse performance by preprocessing
PDF
Everything We Learned About In-Memory Data Layout While Building VoltDB
PPT
demo2.ppt
KEY
ZendCon 2011 Learning CouchDB
PPTX
Database System Concepts AND architecture [Autosaved].pptx
PPT
01 Persistence And Orm
PPTX
Join operation
PPTX
Download different material from slide share
PDF
Introduction to Database Management Systems: Structure, Applications, and Key...
PPTX
The Rise of NoSQL and Polyglot Persistence
PPTX
Data modeling tips from the trenches
PPT
Database intro
PDF
Materialized views in PostgreSQL
PPTX
RDBMS stands for Relational Database Management System
How do You Graph
ITB - UNIT 3.pdf
Chapter 2 Database Systems Architectures
Importance of data model
Architecture of dbms
Dbms viva questions
Improve data warehouse performance by preprocessing
Everything We Learned About In-Memory Data Layout While Building VoltDB
demo2.ppt
ZendCon 2011 Learning CouchDB
Database System Concepts AND architecture [Autosaved].pptx
01 Persistence And Orm
Join operation
Download different material from slide share
Introduction to Database Management Systems: Structure, Applications, and Key...
The Rise of NoSQL and Polyglot Persistence
Data modeling tips from the trenches
Database intro
Materialized views in PostgreSQL
RDBMS stands for Relational Database Management System

Recently uploaded (20)

PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
Tartificialntelligence_presentation.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
project resource management chapter-09.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hybrid model detection and classification of lung cancer
PDF
MIND Revenue Release Quarter 2 2025 Press Release
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Mushroom cultivation and it's methods.pdf
1 - Historical Antecedents, Social Consideration.pdf
Assigned Numbers - 2025 - Bluetooth® Document
SOPHOS-XG Firewall Administrator PPT.pptx
NewMind AI Weekly Chronicles - August'25-Week II
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Enhancing emotion recognition model for a student engagement use case through...
Tartificialntelligence_presentation.pptx
WOOl fibre morphology and structure.pdf for textiles
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Hindi spoken digit analysis for native and non-native speakers
project resource management chapter-09.pdf
Encapsulation_ Review paper, used for researhc scholars
Heart disease approach using modified random forest and particle swarm optimi...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Zenith AI: Advanced Artificial Intelligence
Hybrid model detection and classification of lung cancer
MIND Revenue Release Quarter 2 2025 Press Release

OracleMaterializedviews & Hierarchical Data

  • 1. Oracle Materialized Views For Hierarchical Data Storage And Retrieval.
  • 2. Materialized Views Application Materialized views is well known concept to any oracle pl/sql enthusiast. Lets look at a case study where materialized views are used to achieve the desired result with the expected performance. Storage and Query of Hierarchical Data: Any programmer would have invariably come across the problem of storage and retrieval of data that share a hierarchy among themselves. The most common would be storing location data as in Country>>State>>City. Lets assume for this discussion that a record/node has only one parent. One way to store this data is to have separate table structure for each level i.e. Country, state, city etc. However this method may not be suitable for a rapidly changing system. Let’s say a new country gets added which has further segregation like "Country>>State>>City>>County”. Hence to represent the data one has to add a new table County to the data model in the current design to be able to store the data. Needless to say that one also has to change the retrieval query joins to bring in the new data. An approach to the above problem can be , the above data can be stored in a single table with every record having a reference to its parent record. This approach of representing a tree is commonly known Adjacency list as the parent-child are adjacent to each other.
  • 3. Adjacency List For Location/Place This structure takes care of the variable depth problem of the tree. Hence now data of any depth can be stored without creating new tables to the data model. Another example would be the reporting structure of an employee. A junior employee may have a long chain of supervisors going up to the CEO, where as a CEO may report to only one person.
  • 4. The previous slide structure while adding flexibility does introduce some limitations, most of which can be worked around but at the cost of performance. While queries that involves immediate children, like finding the states in countries or cities in State are very fast, things starts to get messy when one needs to find all the descendants of a node. May be one can use CONNECT BY clause with SYS_CONNECT_BY_PATH to achieve it. But that will need more computation and string comparisons. A more elegant approach would be to make use of Closure Tables to represent the tree. A closure table stores, as records, pair of nodes that have an ancestor/descendant relationship irrespective of the depth or level of the nodes in the tree.
  • 5. Closure Table For Location/Place
  • 6. Hence while adjacency list is more intuitive, closure table performs better for data retrieval of course with some space usage overheads. Now to have the best of both worlds , one may use the adjacency list for accepting data from the User Interface for OLTP systems or by data uploads in DSS systems. Then a materialized view could be used to create the Closure table over the adjacency list table. Every time data is loaded , the materialized view can be refreshed to recreate the closure table. The closure table is used in the joins with other tables in the queries.