I have a schema with many related tables. A view let me agglomerate all these tables in one big table easy to handle for my application.
Now I need to present slightly different views to the application: one more relation to present, some additional columns,
A very simplified example: the real one has many fields and tables related
Base request:
select T1.C1, T2.C2
from T1, T2
where ...
Specialized request A:
select T1.C1, T2.C2, T2.C3, T4.C4
from T1, T2, T4
where ...
Specialized request B:
select T1.C1, T2.C2, T2.C3, T5.C5
from T1, T2, T5
where ...
Do you think it is a good idea (both in maintenance and performance point of view) to create a first view ‘base_view’ and then reuse this view to create view_A and view_B ?
Assuming that you always need to join T1 and T2 then yes, a base view would be a good idea. It will reduce the maintenance cost when you need to add additional views.
The primary danger with a base view is that the base view does work that the specialized results do not. If, for example, the base view joins a third table that specialized requests do not need, then the specialized requests would be less efficient than they could otherwise be. (Note that this depends on the Oracle version and the optimizer– in the latest versions, the optimizer may be able to figure out that a specialized query doesn’t need that third table joined in an eliminate the table from the query plan).