I have split a table into Parent/Child so that we can store multiple versions of the data in the Child table.With the benefit of hindsight I probably should have kept the original single-table and added some sort of child table for "previous versions"The Parent Table has a column for the ID of the "Latest Version of Child record"The purpose of this table is to store the names of Images (ID, Image Name, Height and Width)The new tables are ImageParent, with the original ID and a column for the LatestChildID, and the ImageChild table with ID, Name, Height, Width.We also took the opportunity to add a Type column to the ImageParent table (Static image or Video) - so that's an additional column that I now need in my queryI used to doSELECT *FROM MainTable AS T JOIN Images AS I ON I.ID = T.ImageID
and now I have to doSELECT *FROM MainTable AS T JOIN ImageParent AS P ON P.ID = T.ImageID JOIN ImageChild AS C ON C.ID = P.LatestImageID
and its hurting performance ...So I tried an Indexed View:CREATE VIEW MyImageViewWITH SCHEMABINDINGASSELECT T.ID, T.Type, P.Name, P.Width, P.HeightFROM ImageParent AS P JOIN ImageChild AS C ON C.ID = P.LatestImageIDGOCREATE UNIQUE CLUSTERED INDEX IDX_MyImageView ON dbo.MyImageView( ID)GO
and I've changed my query to be:SELECT *FROM MainTable AS T JOIN MyImageViewAS AS I WITH (NOEXPAND) ON I.ID = T.ImageID
but that is no faster than just joining to the Parent/Child pair of tables. Would you expect that?The Query Plan is clearly using the View and Index.The thing that is bothering me is the I/O Stats, originally:Table 'ImageChild'. Scan count 0, logical reads 132, ...Table 'ImageParent'. Scan count 0, logical reads 128, ...
and the I/o Stats after changing the query to use the view are:Table 'MyImageView'. Scan count 42, logical reads 315, ...
CPU time is about the same, however, but it doesn't seem like an "improvement" to have so many Scans & Logical I/O'sThe actual query is a fair bit more complicated than I have shown, so initially I'm just looking for any general gut feeling suggestions, or advice please.Or maybe I need to do something else to make proper use of Indexed Views? We are using SQL Web edition, not Enterprise.