September 18, 2023 at 12:00 am
Comments posted to this topic are about the item GENERATE_SERIES() Breaks Minimal Logging
--Jeff Moden
Change is inevitable... Change for the better is not.
September 18, 2023 at 3:59 pm
That is a bit scary and odd... have you reported this to MS? If they are aware of it and it is a limitation of the function, they should document it for cases like what you use it for where you are generating a lot of data. It should be documented that generating large series' will result in large transaction logs.
Also, as a thought (I didn't test this but curious if anyone else did) - does "OPTIMIZE FOR UNKNOWN" rather than "RECOMPILE" help with the minimal logging with variables or not? I know when I write stored procedures, I prefer "OPTIMIZE FOR UNKNOWN" rather than "RECOMPILE" IF someone determines that RECOMPILE is "required". All cases I've seen in my department, OPTIMIZE FOR UNKNOWN handles things just as well as RECOMPILE. BUT in my scenario, the stored procedures we write have unique sets of parameters when they are run in most cases.
Once nice thing about what you found is that it SHOULD RARELY have an issue with production level code. I know my prod boxes are ALL set to full recovery if possible (I have 1 3rd party tool that throws errors if it finds its database in full recovery mode and the tool is not managed by me so I was asked to put it into simple recovery mode).
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.
September 18, 2023 at 4:48 pm
It's not as rare as you might think in production code if you use TempDB or a "scratch/working" database to get "balls-out" ( https://en.wiktionary.org/wiki/balls-out ) performance in code, especially when the main database is necessarily in the FULL Recovery Model. We use the technique at work, A LOT!
As for "Optimize for Unknown", I've not tested it. I'll try to get a test in tonight. Thank you for the suggestion! I've not had such "good luck" with it as you apparently have had, but it's worth a try here.
As far as letting MS know... I had the serendipitous opportunity to do so directly this morning, as well as another subject concerning performance in 2022. As for the suggestion site, I'm not likely to make any suggestions there anymore unless MS has had a drastic change in the people evaluating such posts.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2023 at 2:40 pm
Maybe the most efficient way to mockup 100 million rows of randomized test data would be to leverage PowerShell or Python to create text files and then BCP them into the SQL Server table.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
September 19, 2023 at 8:11 pm
Maybe the most efficient way to mockup 100 million rows of randomized test data would be to leverage PowerShell or Python to create text files and then BCP them into the SQL Server table.
Thanks for the feedback, Eric. Always appreciated.
Possibly. The only way to find out is for someone to test that. I'm not the fellow that can do that properly. We need an expert and, again, I don't even qualify a user of either.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 7, 2026 at 9:24 am
DROP TABLE IF EXISTS dbo.BigTable
DECLARE @StartDT DATETIME = '2010'
,@EndDT DATETIME = '2020'
,@Rows INT = 100000000;
DECLARE @Days INT = DATEDIFF(dd,@StartDT,@EndDT)
SELECT ProductID = CHAR(ABS(CHECKSUM(NEWID())%2)+65)
+ CHAR(ABS(CHECKSUM(NEWID())%2)+65)
+ CHAR(ABS(CHECKSUM(NEWID())%2)+65)
,Amount = RAND(CHECKSUM(NEWID()))*100
,Quantity = ABS(CHECKSUM(NEWID())%50)+1
,TransDT = RAND(CHECKSUM(NEWID()))*@Days+@StartDT
INTO dbo.BigTable
FROM GENERATE_SERIES(1,@Rows) --TODO uncomment one or the other FROM clause for different test.
OPTION (USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE')) -- force parallel execution plan
?
takes 0:46 min but it is just an unsorted heap
God is real, unless declared integer.
September 7, 2026 at 4:27 pm
Thanks for the feedback, Thomas. I'll try to see what the differences are. What are you setup for system/database MAXDOP, which edition and version of SQL Server were you using, how much memory is allocated to SQL Server and what's the total memory of the machine (or VLM)?
Also, what was the Recovery Model you were using when you ran it and how much log file did it consume?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 8, 2026 at 8:15 am
CREATE NONCLUSTERED INDEX ic_BigTable__TransDT_ProductId ON dbo.BigTable
(TransDT, ProductId)
WITH (DATA_COMPRESSION = ROW, DROP_EXISTING = OFF, FILLFACTOR = 100, STATISTICS_INCREMENTAL = OFF, SORT_IN_TEMPDB = ON)
ON [PRIMARY]
;
GO?
-- Session 2 (monitoring)
DECLARE @MaxPct decimal(10,2) = 0;
DECLARE @MaxMB decimal(18,2) = 0;
WHILE EXISTS
(
SELECT 1
FROM sys.dm_exec_requests
WHERE session_id = 105 -- session running the main statement
)
BEGIN
SELECT
@MaxPct = CASE
WHEN used_log_space_in_percent > @MaxPct
THEN used_log_space_in_percent
ELSE @MaxPct
END,
@MaxMB = CASE
WHEN used_log_space_in_bytes / 1024.0 / 1024 > @MaxMB
THEN used_log_space_in_bytes / 1024.0 / 1024
ELSE @MaxMB
END
FROM sys.dm_db_log_space_usage;
WAITFOR DELAY '00:00:00.100'; -- 100 ms
END;
SELECT
MaxLogUsedPercent = @MaxPct,
MaxLogUsedMB = @MaxMB;?
God is real, unless declared integer.
September 9, 2026 at 5:21 pm
Thank you, Thomas!!! I really appreciate the details. I start/restart some tests and get back here.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply