Getting Better Performance out of SQL Server Table Variables
OK... So I've got a stored proc that does some searching in the DB. Something like
DECLARE @ResultsOfFTSQuery TABLE (componentid int) IF (@FullTextSearch <> '') BEGIN INSERT @FTSResults SELECT ComponentID FROM Components WHERE CONTAINS (Rendering,@FullTextSearch) END
SELECT TOP 10000 * FROM TheTable WHERE (TheKeyID in (SELECT ComponentID FROM @FTSResults)) AND .....
And the performance gets REALLY bad as the results of the first query increases. Simply adding a PRIMARY KEY to the table variable increased performance from 40 secs down to sub 1 sec.
DECLARE @ResultsOfFTSQuery TABLE (componentid int PRIMARY KEY)
This article notes that you can't have 'real' indexes on table variables, but if you create a PRIMARY KEY or UNIQUE contstraint you get one for free.
I'm off to spend some time trying to find other procs I can optimise 
.NET|Monday, May 16, 2005 8:53:49 AM UTC||Tracked by: "video strip poker 1.43 crack andnot on line online" (video strip poker 1.43 cra... [Trackback] "casino" (casino) [Trackback]
|