Optimizing view to read rows as per usage statistics

oracleview

There are two modules in the project:

Module 1: patient registration module

patient_admitted table holds information of patient admitted in hospital. patient_id is primary key.

patient_discharged table holds information of patient that got discharged from the hospital.

patient_personal_details view represents patient personal information from patient_admitted table such as name,age,gender etc.
It also reads from patient_discharged table in scenario as below:
A row in patient_admitted table is moved to patient_discharged table once the patient gets discharged, If medical_reports table consists such row then the view retains that row information by reading it from patient_discharged table.

Module 2: Medical test module

medical_reports table holds medical report details of patient along with the personal information. If the patient is currently admitted then it reads the personal information from the patient_personal_details view.

Problem- Optimization needed:

Over the time the view would read bulk records from patient_discharged table.
Is it possible to discard records(row) in patient_personal_details view that haven't been accessed from past 120 days using some access statistics.

If there better way to design such scenario please suggest.

Best Answer

This sounds like you want to build a materialized view that satisfies your data condition. A materialized view (previously called a snapshot) physically stores a copy of the data rather than a standard view which is simply a query on the underlying tables. You should get some benefit when querying as the older records will not be in the view and you can define indexes appropriate specifically to viewing.

There are lots of options and restrictions around refreshing of these views and you will need to do some research to establish the right approach in your situation. https://docs.oracle.com/cd/B28359_01/server.111/b28326/repmview.htm