which is best materialized view or table with SP? and why?
Loading
which is best materialized view or table with SP? and why?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaish MathewsPosted Feb 5, 2025, 12:03 PM
The choice between a Materialized View and a Table with a Stored Procedure (SP) depends on the use case, performance requirements, and how frequently the data needs to be updated.
1. Materialized View
A Materialized View (MV) is a precomputed result set that is stored physically and can be refreshed periodically.
Pros:
ON COMMITorON DEMAND).Cons:
FAST,COMPLETE, orINCREMENTALrefresh).2. Table with Stored Procedure
A Table with an SP means creating a table to store precomputed results and using a stored procedure to update/populate the table.
Pros:
Cons:
Which One is Best?
When to Use What?
Use Materialized View if:
Use Table with SP if:
Tuhin PaulPosted Feb 5, 2025, 3:41 PM
Why Use a Table with a Stored Procedure?
Implementation
Create the Table
Create the Stored Procedure
Execute the Stored Procedure Run the stored procedure manually or schedule it using a job scheduler:
Query the Table
Advantages
Disadvantages
Choose Materialized View If:
Choose Table with Stored Procedure If:
Tuhin PaulPosted Feb 5, 2025, 2:56 PM
Both Materialized Views and Tables with Stored Procedures (SP) have their own use cases, advantages, and disadvantages. The choice between them depends on the specific requirements of your application, such as performance, data freshness, and complexity.
There is a common case for example a retail company wants to generate a daily sales report for all stores. The report includes:
The company needs to decide whether to use a Materialized View or a Table with a Stored Procedure to generate this report.
Why Use a Materialized View?
Implementation
Create the Materialized View
Refresh the Materialized View Schedule a daily refresh using a database job (e.g., in PostgreSQL or Oracle):
Query the Materialized View
Advantages
Disadvantages