I am creating a view with two very large data sets numbering the millions of rows. I have joining the two tables together using a full outer join and group by some of the columns.
I have a field id column common to both tables that I need users to be able to filter the view on. Originally, I was using TableA.F_ID = TableB.F_ID in the outer join syntax and that performed very well. However, if there were F_ID rows in TableB that were not in TableA they would not be displayed unless I used
where TableA.F_ID = <VALUE> or TableB.ID = <VALUE>
To get around having to use the or clause I used the fable that F_ID comes from in the query via an inner join to filter the data. This method does work but it has to execute the select on TABLEA and TABLEB before filtering out the rows and the query is taking 10+ minutes to return.
Based on the query below is there a way to optimize this to get a quicker end result?
select fm.F_ID
,fad.A
,fad.B
,fad.C
,fac.A
,fac.B
,fac.C
,fab.SUM as FAB_SUM
,fac.SUM as FAC_SUM
from V_FAB_COMBINED_GROUPS fad
FULL OUTER JOIN V_LTB_ALL_GROUPED fac on
fab.F_ID = fac.F_ID
and fac.A = fab.A
and fac.B = fab.B
and fac.C = fab.C
inner join fm on (fm.F_ID = fab.F_ID or fm.F_ID = fac.F_ID)
where fm.F_ID = 1
coalesce(fab.f_id, fac.f_id) f_idas a column in the view? That way, users could just doand f_id = ...when they query against the view? - Boneist