I have the following indexed view:
CREATE VIEW [dbo].[campaignContacts] WITH SCHEMABINDING
SELECT cs.campaignId, sc.contactId, COUNT_BIG(*) AS total
FROM dbo.campaignSources cs
INNER JOIN dbo.sources s ON s.id = cs.sourceId
INNER JOIN dbo.sourceContacts sc ON sc.sourceId = s.id
GROUP BY cs.campaignId, sc.contactId
CREATE UNIQUE CLUSTERED INDEX [IX_campaignContacts] ON [dbo].[campaignContacts]
Now, when I do a simple SELECT contactId FROM campaignContacts it still takes a few seconds to compute the query before delivering results (these are big tables), and in the execution plan the index is not used.
I think I'm probably misunderstanding something critical about indexed views here, but surely if there is an index that already has the data I'm looking for, it should be used?