Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Update statistics in parallel Expand / Collapse
Author
Message
Posted Sunday, January 27, 2013 5:16 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:19 AM
Points: 33, Visits: 292
Comments posted to this topic are about the item Update statistics in parallel
Post #1412153
Posted Monday, January 28, 2013 2:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Today @ 5:51 PM
Points: 1, Visits: 135
I've corrected the SQL to include the schema name:

SELECT  t.name AS [tname] ,
' update statistics ' + sch.name + '.[' + t.name + '] ' [comando]
FROM sys.tables t
INNER JOIN sys.schemas sch ON sch.schema_id = t.schema_id
LEFT JOIN sys.stats s ON t.object_id = s.object_id
JOIN ( SELECT object_id ,
SUM(rows) rows
FROM sys.partitions
GROUP BY object_id
HAVING SUM(rows) > 0
) pa ON t.object_id = pa.object_id
WHERE ( STATS_DATE(t.object_id, stats_id) IS NULL
OR DATEDIFF(DAY, STATS_DATE(t.object_id, stats_id), GETDATE()) >= 3
)
GROUP BY sch.name ,
t.name
ORDER BY 1

Post #1412278
Posted Monday, January 28, 2013 4:50 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:19 AM
Points: 33, Visits: 292
Good correction !
Post #1412345
Posted Monday, January 28, 2013 1:49 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 5:36 PM
Points: 217, Visits: 1,009
Great job!

One more fix:
SELECT  REPLACE(REPLACE(sch.name + '_' + t.name, '[', '_'), ']', '_') AS [tname] ,
' update statistics ' + QUOTENAME(sch.name) + '.' + QUOTENAME(t.name) [comando]
FROM sys.tables t
INNER JOIN sys.schemas sch ON sch.schema_id = t.schema_id
LEFT JOIN sys.stats s ON t.object_id = s.object_id
JOIN ( SELECT object_id ,
SUM(rows) rows
FROM sys.partitions
GROUP BY object_id
HAVING SUM(rows) > 0
) pa ON t.object_id = pa.object_id
WHERE ( STATS_DATE(t.object_id, stats_id) IS NULL
OR DATEDIFF(DAY, STATS_DATE(t.object_id, stats_id), GETDATE()) >= 3
)
GROUP BY sch.name ,
t.name
ORDER BY 1




Alex Suprun
Post #1412640
Posted Monday, January 28, 2013 4:54 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 10:48 PM
Points: 482, Visits: 889
Wow, spinning up SSIS tasks on the fly to take advantage of multithreading. This is exploding my mind at the possibilities.

Thanks for this article, it's a great example to explain this technique. I like that your code considers maximum threads and error handling, I can see the biggest danger might be creating too many packages or falling into some loop of continuous package creation.

Have you recorded some performance metrics of this technique versus using the stored proc to update stats one at a time?
Post #1412703
Posted Tuesday, January 29, 2013 2:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:19 AM
Points: 33, Visits: 292
Thanks to Alexander for the fix.
About performance metrics :
in general, my update statistics runs N times faster than built-in sp_updatestats , where N is number of threads .
I think that N= 5/10 is good for most purposes ... anyway consider that updating statistics in this way is a task that makes heavy use of db resources, to perform his task faster than the dedicated built-in does
Post #1412847
Posted Saturday, February 2, 2013 12:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 17, 2014 5:15 AM
Points: 5, Visits: 239
Part of our current daily db maintenance is a sql script that reads through all indexes in a db and determines if they need a reorg or rebuild, or no maintenance required. Problem there is the script runs serially. We have time in our schedule to do this, but it's always great to get things running quicker.

Can anyone think of a reason you couldn't use this same technique to create a list of reorg or rebuild commands, create a sql task for each, and therefore take advantage of the parallelism demonstrated here?
Post #1414916
Posted Tuesday, February 5, 2013 8:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:19 AM
Points: 33, Visits: 292
chadmjordan (2/2/2013)
Part of our current daily db maintenance is a sql script that reads through all indexes in a db and determines if they need a reorg or rebuild, or no maintenance required. Problem there is the script runs serially. We have time in our schedule to do this, but it's always great to get things running quicker.

Can anyone think of a reason you couldn't use this same technique to create a list of reorg or rebuild commands, create a sql task for each, and therefore take advantage of the parallelism demonstrated here?


There should be no problem, but consider that rebuilding an index is , in general, much heavier task than update statistics, so I thin you will not be able to use a large number of threads, but you could try with 4/5 , it would speed up your script 4/5 times ...
Post #1415899
Posted Wednesday, March 27, 2013 12:42 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, November 5, 2014 11:41 PM
Points: 406, Visits: 778
Hi Federico, I gave this a try.

We have daily tasks running in our system. Every day at a specific time, we truncate certain tables and repopulate them. We have to update statistics for these tables.

I've written a script which queries sysindexes and finds out the tables which were modified. I integrated that with the script in your article to return tname and comando. This should work very well. However, I get a runtime error. I'm not very good at SSIS. Can you please help me out?

I have attached screenshots of the error. The error says "the source code cannot be displayed". I think the parent package is not able to reference the child package. If I add the child package to the solution and try to execute the child package alone, it works alright.

And when we say
app.SaveToXml(packageName + ".dtsx", dataTransferPackage, Nothing)

does the package always get saved within the project directory? How do I deploy this to server? I want to schedule this as a job in the server.


  Post Attachments 
error1.JPG (2 views, 96.23 KB)
error2.JPG (2 views, 132.52 KB)
Post #1435782
Posted Wednesday, March 27, 2013 6:00 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 3:19 AM
Points: 33, Visits: 292
Arjun Sivadasan (3/27/2013)
Hi Federico, I gave this a try.

We have daily tasks running in our system. Every day at a specific time, we truncate certain tables and repopulate them. We have to update statistics for these tables.

I've written a script which queries sysindexes and finds out the tables which were modified. I integrated that with the script in your article to return tname and comando. This should work very well. However, I get a runtime error. I'm not very good at SSIS. Can you please help me out?

I have attached screenshots of the error. The error says "the source code cannot be displayed". I think the parent package is not able to reference the child package. If I add the child package to the solution and try to execute the child package alone, it works alright.

And when we say
app.SaveToXml(packageName + ".dtsx", dataTransferPackage, Nothing)

does the package always get saved within the project directory? How do I deploy this to server? I want to schedule this as a job in the server.

Arjun ,
1) please send me the TSQL code that returns tname and comando , I think the problem is there
2) app.SaveToXml saves to the same directory where is the master DTSX
3) If you want this all to run on the server, you should preferably, as I have done, build a bat file that runs the master DTSX , saved in a dedicated directory on the database server
This will not work if the master DTSX is saved into the SQlSever database , the DTSX must be saved in the filesystem

Post #1435850
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse