Syringe.Net.Nz
Irregular Injection of Opinion
RSS 2.0|Atom 1.0|CDF

 Monday, May 16, 2005
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|Comments [72]|Tracked by:
"video strip poker 1.43 crack andnot on line online" (video strip poker 1.43 cra... [Trackback]
"casino" (casino) [Trackback]
   
Wednesday, February 15, 2006 5:25:12 PM UTC
1
Wednesday, February 15, 2006 5:29:26 PM UTC
2
Friday, June 23, 2006 7:26:14 AM UTC
mortgage
Saturday, July 22, 2006 10:43:56 AM UTC
hello! http://nissan-sentra-np.blogspot.com/ http://nissan-xterra-np.blogspot.com/ http://nissan-altima-np.blogspot.com/ http://nissan-350z-np.blogspot.com/
Emanuel
Tuesday, July 25, 2006 9:38:45 AM UTC
debt consolidation
Saturday, August 05, 2006 8:34:29 AM UTC
home equity line of credit
Saturday, August 05, 2006 8:58:48 AM UTC
refinance
Tuesday, August 08, 2006 9:08:07 AM UTC
home equity loans
Thursday, August 10, 2006 11:53:11 PM UTC
refinancing
Saturday, August 12, 2006 10:00:38 PM UTC
refinance
Sunday, August 13, 2006 9:20:24 AM UTC
home mortgages
Sunday, August 13, 2006 9:55:25 AM UTC
home loans
Monday, August 14, 2006 5:04:32 AM UTC
Honest work never hurt.
Friday, August 18, 2006 8:17:07 PM UTC
home equity line of credit
Sunday, August 20, 2006 9:25:29 AM UTC
refinance
Tuesday, August 22, 2006 6:19:14 AM UTC
home equity loans
Tuesday, August 29, 2006 9:40:13 PM UTC
http://mednet365.com/lortab/lortab.html
http://mednet365.com/clonazepam/clonazepam.html
http://mednet365.com/xanax/xanax.html
http://mednet365.com/cialis/cialis.html
http://mednet365.com/ativan/ativan.html
Sunday, September 03, 2006 11:13:58 AM UTC
Thank you!
Thursday, September 07, 2006 6:00:28 AM UTC
Thank you!
Thursday, September 07, 2006 9:45:41 PM UTC
Trouble shared is trouble halved,joy shared is joy doubled.
Friday, September 08, 2006 1:57:38 AM UTC
Thank you!
Friday, September 08, 2006 4:20:24 AM UTC
Thank you!
Friday, September 08, 2006 4:23:05 AM UTC
Thank you!
Friday, September 08, 2006 10:40:22 PM UTC
Whoever has walked with truth generates life.
Saturday, September 09, 2006 7:40:02 AM UTC
Thank you!
Sunday, September 10, 2006 9:08:53 AM UTC
Virginity like bubble, one prick, all gone.
Sunday, September 10, 2006 8:47:15 PM UTC
Thank you!
Wednesday, September 13, 2006 11:57:28 PM UTC
Thank you!
Saturday, September 16, 2006 5:23:05 AM UTC
Schwarzbrot macht Wangen rot, Weissbrot macht Leute tot.
Saturday, September 16, 2006 5:23:27 AM UTC
Time is money.
Saturday, September 16, 2006 12:59:11 PM UTC
Thank you!
Monday, September 18, 2006 11:23:04 PM UTC
Thank you!
Tuesday, September 19, 2006 3:03:30 PM UTC
Dark bread makes cheeks red, white bread makes people dead.
Wednesday, September 20, 2006 2:06:03 AM UTC
Aller guter Dinge sind drei.
Wednesday, September 20, 2006 2:07:15 AM UTC
Madchen, die pfeifen und Hennen (Hahnen), die krahn, soll man beizeiten den Hals herumdrehn.
Wednesday, September 20, 2006 7:48:16 PM UTC
Gluck im Spiel, Ungluck in der Liebe.
Wednesday, September 20, 2006 7:48:29 PM UTC
Trouble shared is trouble halved,joy shared is joy doubled.
Wednesday, September 20, 2006 7:52:24 PM UTC
Trouble shared is trouble halved,joy shared is joy doubled.
Wednesday, September 20, 2006 7:52:32 PM UTC
Gluck im Spiel, Ungluck in der Liebe.
Wednesday, September 20, 2006 7:57:20 PM UTC
Gluck im Spiel, Ungluck in der Liebe.
Friday, September 22, 2006 2:34:21 AM UTC
A man is known by the friends he keeps.
Friday, September 22, 2006 2:34:39 AM UTC
Time is money.
Friday, September 22, 2006 8:17:29 PM UTC
Madchen, die pfeifen und Hennen (Hahnen), die krahn, soll man beizeiten den Hals herumdrehn.
Saturday, September 23, 2006 1:36:35 AM UTC
If you have to do it, you might as well do it right.
Saturday, September 23, 2006 1:37:38 AM UTC
If you have to do it, you might as well do it right.
Sunday, September 24, 2006 12:10:10 AM UTC
Gluck im Spiel, Ungluck in der Liebe.
Monday, September 25, 2006 10:25:31 PM UTC
Aller guter Dinge sind drei.
Tuesday, September 26, 2006 6:20:06 PM UTC
Don't put off till tomorrow, what you can do today.
Tuesday, September 26, 2006 6:20:10 PM UTC
Zeige mir Deine Freunde und ich sage Dir wer Du bist.
Wednesday, September 27, 2006 4:11:19 AM UTC
Die Axt im Haus erspart den Zimmermann.
Thursday, September 28, 2006 2:46:00 AM UTC
Aller guter Dinge sind drei.
Thursday, September 28, 2006 2:46:32 AM UTC
Don't put off till tomorrow, what you can do today.
Friday, September 29, 2006 11:30:02 AM UTC
Alter schutzt vor Torheit nicht.
Saturday, September 30, 2006 12:55:13 PM UTC
Anti-Anxiety Aromatherapy: blend 3 drops neroli,2 drops patchouli,2 drops geranium,2 drops rose,2 drops ylang-ylang,1 drop frankincense,1 drop bergamot
Monday, October 02, 2006 9:58:24 PM UTC
If you have to do it, you might as well do it right.
Wednesday, October 04, 2006 12:16:03 AM UTC
Anti-Anxiety Aromatherapy: blend 3 drops neroli,2 drops patchouli,2 drops geranium,2 drops rose,2 drops ylang-ylang,1 drop frankincense,1 drop bergamot
Thursday, October 05, 2006 2:55:18 AM UTC
Time is money.
Thursday, October 05, 2006 2:55:22 AM UTC
A whistling girl and a crowing hen always come to a bad end.
Thursday, October 05, 2006 2:57:07 AM UTC
Jedes Ding hat seine zwei Seiten.
Thursday, October 05, 2006 2:59:01 AM UTC
Schwarzbrot macht Wangen rot, Weissbrot macht Leute tot.
Thursday, October 05, 2006 3:00:15 AM UTC
Gluck im Spiel, Ungluck in der Liebe.
Thursday, October 05, 2006 3:00:23 AM UTC
Time is money.
Thursday, October 05, 2006 3:01:33 AM UTC
Jedes Ding hat seine zwei Seiten.
Thursday, October 05, 2006 3:03:27 AM UTC
Zeit ist Geld.
Thursday, October 05, 2006 3:04:50 AM UTC
Don't put off till tomorrow, what you can do today.
Monday, October 16, 2006 1:13:39 AM UTC
Zeige mir Deine Freunde und ich sage Dir wer Du bist.
Monday, October 23, 2006 6:19:27 AM UTC
Thank you!
Monday, October 23, 2006 6:21:41 AM UTC
Thank you!
Monday, October 23, 2006 6:22:56 AM UTC
Thank you!
Monday, October 23, 2006 12:55:06 PM UTC
Thank you!
Monday, October 23, 2006 5:24:05 PM UTC
Thank you!
Tuesday, October 31, 2006 12:53:11 AM UTC
Great site. Keep doing.
Comments are closed.