|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, July 25, 2012 10:16 AM
Points: 37,
Visits: 114
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Wednesday, July 25, 2012 10:16 AM
Points: 37,
Visits: 114
|
|
FredFlintst0ne (3/10/2010)
Here's a puzzling table variable speed behavior that I can't explain. I have a user-defined table function that returns a small resultset (~200 rows). The user-defined table function employs a GROUP BY in a query of a very large table (say, 1,000,000 rows). When I merely select from the user-defined table function, the small resultset of ~200 rows is returned in ~5 seconds. --psuedocode SELECT myColumn FROM udtReturningSmallResultsetFromGroupByOverLargeNumberOfRecords (@myDateVariable)
However, when I try to insert this small resultset into a table variable, the query below takes about 30 seconds --psuedocode DECLARE @tblVariable TABLE(myColumn varchar(50) NOT NULL)
INSERT @tblVariable(myColumn) SELECT myColumn FROM udtReturningSmallResultsetFromGroupByOverLargeNumberOfRecords (@myDateVariable)
Does anyone have any ideas why inserting such a small resultset into a table variable (~200 records) would cause a 6-fold slowdown? Lacking a good explanation, I can only guess that the presence of the table variable insert is somehow throwing off the optimizer for the user-defined table function select.
I should be more specific. If I run a similar query to the above in 2005, it returns in under 1 second. When I ran it in 2008, it took over a minute and a half. It seems to be a known issue and hopefully there will be a fix soon.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:32 AM
Points: 1,
Visits: 19
|
|
I had the same problem under sql server 2008r2 SP1 (both 32 and 64 bit)! Start parameter -T4130 seems to solve the problem. But i am wondering, because that hotfix (and so the trace flag 4130) is only documented for sql server 2008!?!
Or do i have overseen something?
Regards
Eyck
|
|
|
|