For starters you probably want to change UNION
into UNION ALL
?!?
To have the server do what you want you could add the NOEXPAND
table hint in the 'final' view; but to be honest I've never seen it being beneficial to overall performance.
I'm wondering how smart the query optimizer would be if you tried something along the lines of :
;WITH facts (dimension_ids & measures)
AS (Select * from [Sales actuals]
UNION ALL
Select * from [Sales targets]
UNION ALL
Select * from [Stocks]
UNION ALL
Select * from [Inbound])
SELECT dimension_values, measures
FROM facts
JOIN dimension1 ON dim1.id = facts.dim1_id
AND dim1.property = @filter_dim1
JOIN dimension2 ON dim2.id = ...
etc...
It probably would do what you want, although I'm not convinced it would be better than
SELECT dimension_values, measures
FROM [Sales actuals] fct
JOIN dimension1 ON dim1.id = fct.dim1_id
AND dim1.property = @filter_dim1
JOIN dimension2 ON dim2.id = ...
UNION ALL
SELECT dimension_values, measures
FROM [Sales targets] fct
JOIN dimension1 ON dim1.id = fct.dim1_id
AND dim1.property = @filter_dim1
JOIN dimension2 ON dim2.id = ...
UNION ALL
etc...
which --going by your explanation-- is what you're running up against and apparently has terrible performance ?
PS: I know this will sound 'basic', but did you run sp_updatestats first ?