April 13, 2011 at 6:47 am
Ninja's_RGR'us (4/13/2011)
mister.magoo (4/13/2011)
That is definitely one to remember! Glad it worked for you as well, as there was the possibility in my mind that it might be version specific.I am using Microsoft SQL Server 2008 (SP2) - 10.0.4000.0 (Intel X86) Sep 16 2010 20:09:22 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition on Windows NT 6.1 <X86> (Build 7600: )
... and I've been playing around with your idea and it's really the varchar that seems to clinch it on top of prepending. Anything as nvarchar in there and it shoots back up to 1 minute+.
Microsoft SQL Server 2005 - 9.00.4035.00 (SP3) (Intel X86) Nov 24 2008 13:01:59 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
Maybe we do have some version specific issues then because on mine, prepending is definitely required - conversion to varchar alone doesn't help....
I might try it on SQL2005 as well...
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
April 13, 2011 at 6:49 am
mister.magoo (4/13/2011)
Ninja's_RGR'us (4/13/2011)
mister.magoo (4/13/2011)
That is definitely one to remember! Glad it worked for you as well, as there was the possibility in my mind that it might be version specific.I am using Microsoft SQL Server 2008 (SP2) - 10.0.4000.0 (Intel X86) Sep 16 2010 20:09:22 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition on Windows NT 6.1 <X86> (Build 7600: )
... and I've been playing around with your idea and it's really the varchar that seems to clinch it on top of prepending. Anything as nvarchar in there and it shoots back up to 1 minute+.
Microsoft SQL Server 2005 - 9.00.4035.00 (SP3) (Intel X86) Nov 24 2008 13:01:59 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
Maybe we do have some version specific issues then because on mine, prepending is definitely required - conversion to varchar alone doesn't help....
I might try it on SQL2005 as well...
I guess I wasn't clear. It takes both. Prepending alone is not enough, it takes EVERYTHING varchar. Even a single nchar in there screws it up again.
April 13, 2011 at 6:54 am
Posting final code... prepending with "correct" order of the tables...
DECLARE @Exec VARCHAR(MAX)
SELECT @Exec = ''
SELECT @Exec = 'UPDATE STATISTICS dbo.[' + CONVERT(VARCHAR(200),name) + '] WITH FULLSCAN ; ' + CHAR(13) + CHAR(10) + @Exec FROM sys.tables ORDER BY name DESC
PRINT LEN(@Exec)
PRINT @Exec
--EXEC (@Exec)
--27 minutes to run on 18 GB db, over 33 000 stats to update, on very slow time of day.
April 13, 2011 at 6:58 am
Ninja's_RGR'us (4/13/2011)
I guess I wasn't clear. It takes both. Prepending alone is not enough, it takes EVERYTHING varchar. Even a single nchar in there screws it up again.
Oh, right - yes - all VARCHAR is a requirement for this to work quickly - agreed.
And thanks for posting the final code - I will definitely be using this in the future !
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
April 13, 2011 at 7:05 am
mister.magoo (4/13/2011)
Ninja's_RGR'us (4/13/2011)
I guess I wasn't clear. It takes both. Prepending alone is not enough, it takes EVERYTHING varchar. Even a single nchar in there screws it up again.
Oh, right - yes - all VARCHAR is a requirement for this to work quickly - agreed.
And thanks for posting the final code - I will definitely be using this in the future !
Ya, it's simple but you got to remember to do order by DESC to get the ASC order :w00t:.
April 13, 2011 at 8:10 am
Does the order really matter?
April 13, 2011 at 8:17 am
Ninja's_RGR'us (4/12/2011)
How much data did you test with? I have over 8300 tables to concatenate. On top of that the table names or fairly long, here's an "average" name.
Certainly not enough to match 8300 long table names. I'll setup a test, though.
Having a {gasp!} case sensitive DB shouldn't matter for this concatenation.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 13, 2011 at 8:18 am
Brandie Tarvin (4/13/2011)
Does the order really matter?
It actually could. If it fails to finish in the allowed time I need to be able to start back where it was.
If you know which statement failed (IE syntax or whatknot), you can restart the sequence from there on a manual run later on.
April 13, 2011 at 8:20 am
Jeff Moden (4/13/2011)
Ninja's_RGR'us (4/12/2011)
How much data did you test with? I have over 8300 tables to concatenate. On top of that the table names or fairly long, here's an "average" name.Certainly not enough to match 8300 long table names. I'll setup a test, though.
Having a {gasp!} case sensitive DB shouldn't matter for this concatenation.
Thank god for SQL PROMPT and the toolbelt for that matter!!! (not on 2008 yet and can't use 2008 to connect on 2005 for intellisense :sick:).
My final string size is around 670K. And if you read the statistics IO you get almost 0.6 TB of processed pages!!! :w00t:
April 13, 2011 at 8:28 am
Ninja's_RGR'us (4/13/2011)
Brandie Tarvin (4/13/2011)
Does the order really matter?It actually could. If it fails to finish in the allowed time I need to be able to start back where it was.
If you know which statement failed (IE syntax or whatknot), you can restart the sequence from there on a manual run later on.
In that case, (IIRC) Brandi is spot on with storing the individual commands (or perhaps just the table names) in a table and running a WHILE loop over it. A WHILE loop isn't going to kill anything for speed here and a proc that uses it could take an optional parameter of which table it should start with.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 13, 2011 at 8:30 am
Ninja's_RGR'us (4/13/2011)
Brandie Tarvin (4/13/2011)
Does the order really matter?It actually could. If it fails to finish in the allowed time I need to be able to start back where it was.
If you know which statement failed (IE syntax or whatknot), you can restart the sequence from there on a manual run later on.
Ah. I forgot about the human factor needs. I was too busy trying to figure out how order affected the performance. @=)
April 13, 2011 at 8:31 am
Jeff Moden (4/13/2011)
Ninja's_RGR'us (4/13/2011)
Brandie Tarvin (4/13/2011)
Does the order really matter?It actually could. If it fails to finish in the allowed time I need to be able to start back where it was.
If you know which statement failed (IE syntax or whatknot), you can restart the sequence from there on a manual run later on.
In that case, (IIRC) Brandi is spot on with storing the individual commands (or perhaps just the table names) in a table and running a WHILE loop over it. A WHILE loop isn't going to kill anything for speed here and a proc that uses it could take an optional parameter of which table it should start with.
I'd stick it all in a job that also scanned for new tables (and added them to the table) before running the code.
April 13, 2011 at 8:33 am
Brandie Tarvin (4/13/2011)
Ninja's_RGR'us (4/13/2011)
Brandie Tarvin (4/13/2011)
Does the order really matter?It actually could. If it fails to finish in the allowed time I need to be able to start back where it was.
If you know which statement failed (IE syntax or whatknot), you can restart the sequence from there on a manual run later on.
Ah. I forgot about the human factor needs. I was too busy trying to figure out how order affected the performance. @=)
Agreed, but I'm on a yellow light to run this... just because I'm seeing discrepencies between estimates and actual # of rows in 1 query.
Now since running fullscan updates on the whole db runs in less than 30 minutes I'll just leave it as is for now. My immediate problem solved.
My real intent was to implement it in my reindexing job from sql fool. But I didn't want to mess with it. Moreover I only have 4-5 index rebuild / day and all the rest is reorganize. So updating everything is not that much longer at this point.
Case closed for me... even if it's not perfect by my book.
April 14, 2011 at 8:57 am
Gotta say that I am absolutely stunned that we have spent this much effort to try to concatenate a string that has a cursor-driven solution that offers many benefits:
1) incredibly simple to code
2) negligible performance 'hit', ESPECIALLY compared to the relatively HUGE amount of time the actual work will take!!!!!!!
3) offers the ability to run multiple windows for concurrent execution of the work by simple name or object_id range partitioning of the cursor. Yes, you can do this with an exectuted built string too.
4) doesn't suffer from the large compile time and huge plan that will happen when you try to execute that 670K string. I wouldn't be surprised if the compile time didn't take longer than the 'overhead' associated with the cursor.
This is definitely a case where I say use the right tool for the job and I strongly believe that a cursor is the right tool for the job! 😎
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 14, 2011 at 9:02 am
No doubt there.
That was supposed to be a quick 2 minutes "job" to test the outcome of full recompile.
I'm well aware of logging limits and single thread, but why I really started the thread was more a wtf is going on here???
Enjoy.
Viewing 15 posts - 31 through 45 (of 52 total)
You must be logged in to reply to this topic. Login to reply