Could you please share me some light on how to optimise my query in my Oracle (11G) database?
In my database I have 10 temporal tables (TemporalTable_1 to TemporalTable_10) where the schema is similar to follow:
Create table TemporalTable_1 (
Customer_ID number(8),
< Other columns>
valid_period_start timestamp,
valid_period_end timestamp,
period for valid_period(valid_period_start, valid_period_end)
)
Each table have following two indexes and ...
Create index ind_TemporalTable_1_ID on TemporalTable_1 (Customer_ID);
Create index ind_TemporalTable_1_Period on TemporalTable_1 (valid_period_start, valid_period_end);
... a view for result as at a particular date
Create or replace view TemporalTable_1_20200707 as
select
*
from
TemporalTable_1 as of period for valid_period to_date('20200707','yyyymmdd');
TemporalTable_2 to TemporalTable_10 also have the similar indexes and view as TemporalTable_1.
Now I have created a view to join all temporal tables together as at 07 JUL 2020.
Crete view All_Temporals_20200707 as
select
*
from
TemporalTable_1_20200707 TT1
left join TemporalTable_2_20200707 TT2 on
TT2.Customer_id = TT1.Customer_id
left join TemporalTable_3_20200707 TT3 on
TT2.Customer_id = TT3.Customer_id
left join TemporalTable_4_20200707 TT4 on
TT3.Customer_id = TT4.Customer_id
left join TemporalTable_5_20200707 TT5 on
TT4.Customer_id = TT5.Customer_id
left join TemporalTable_6_20200707 TT6 on
TT5.Customer_id = TT6.Customer_id
left join TemporalTable_7_20200707 TT7 on
TT6.Customer_id = TT7.Customer_id
left join TemporalTable_8_20200707 TT8 on
TT7.Customer_id = TT8.Customer_id
left join TemporalTable_9_20200707 TT9 on
TT8.Customer_id = TT9.Customer_id
left join TemporalTable_10_20200707 TT10 on
TT9.Customer_id = TT10.Customer_id
I found that the performance of the view is horrible. And I just don't know how to improve the performance of the query. Result from "Explain plan" indicated that Oracle is not going to use those indexes. For the view "All_Temporals_20200707"
I have also modified the query under view as follow
select /*+ INDEX(TemporalTable_1.IND_TemporalTable_1_PERIOD) */
*
from
TemporalTable_1 as of period for valid_period sysdate; -- today is 07 JUL 2020
However, it makes no differences. This means all indexes I have created have not been used.
Could anyone here share me some light on what should I do to fix the performance issue?
Thanks in advance!
Just to provide some background here, this is actually trying to create a snapshot of the entire database in a daily bases for reporting services. The "All_Temporals_20200707" is actually a query for one of the reports in the real world. This also means the Customer_Id is actually a primary key in the production database for some tables.
