So... I have a large db designed to support "full text search" for documents that I manage, and I have been researching an issue of slowness when trying to do some of the searches. I have discovered that the synonyms in my query appear to have a significant (negative) impact on performance.
Set up:
2 dbs:
1 - Doc info and metadata
2 - Indexing info
Synonyms are used to 'link' the dbs together so I don't have to hardcode db names into each. Which allows me to have differently named pairs of these dbs for testing/dev/etc.
Query in question:
With synonym indexdb | Without synonym IndexDb.dbo:
(
Select EntryId From indexdb.tbl_EntryTokenSummary with(nolock) Where TokenId = indexdb.GetTokenId(4,518529899282903344,898) and (substring(BitMask,1,1) & 8) = 8
Union
Select EntryId From indexdb.tbl_EntryTokenSummary with(nolock) Where TokenId = indexdb.GetTokenId(4,518529899282903345,899) and (substring(BitMask,1,1) & 8) = 8
Union
Select EntryId From indexdb.tbl_EntryTokenSummary with(nolock) Where TokenId = indexdb.GetTokenId(4,518529899282903346,900) and (substring(BitMask,1,1) & 8) = 8
)
Intersect
(
Select EntryId From indexdb.tbl_EntryTokenSummary with(nolock) Where TokenId = indexdb.GetTokenId(4,2608536602748007472,7636274)
Union
Select EntryId From indexdb.tbl_EntryTokenSummary with(nolock) Where TokenId = indexdb.GetTokenId(4,2622845642773639265,28336751)
)
Option(Recompile)
I ran this query with synonyms, without, and again with and got very different time performance. On the surface, the query plan looks the same:
Is there something I am missing about synonyms?
Why would they affect performance so much?
My current plan is to just 'translate' the aliases before I run the query... are there better options?
Thanks!
seventhnight