January 25, 2019 at 3:30 am
First, the sample data script:
-- Create a sample data set
IF OBJECT_ID('tempdb..#SampleData') IS NOT NULL DROP TABLE #SampleData;
WITH
E1 (N) AS (SELECT 1 FROM (VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) d (n)), -- 10 rows
E2 (N) AS (SELECT 1 FROM E1 a, E1 b), -- 100 rows
E4 (N) AS (SELECT 1 FROM E2 a, E2 b), -- 10000 rows
E8 (N) AS (SELECT 1 FROM E4 a, E4 b) -- 100000000 rows
SELECT TOP(1000000)
[Timestamp] = DATEADD(DAY,CHECKSUM(NEWID()) % 10,GETDATE()),
[Tagname] = 'NC_S\Column ' + CAST(1 + (ABS(CHECKSUM(NEWID())) % 900) AS VARCHAR(20)),
[Value] = ABS(CHECKSUM(NEWID())) % 1000
INTO #SampleData
FROM E8;
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 25, 2019 at 3:41 am
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 25, 2019 at 3:50 am
Finally, four conditions to test:
without preagg, single key clustered index: stream aggregate, 00:01:30
without preagg, dual key clustered index: stream aggregate, 00:01:26
with preagg, single key clustered index: hash aggregate x2, 00:00:05
with preagg, dual key clustered index: stream aggregate x2, 00:00:03
Conclusions:
Preaggregation with the right index is, in this test harness, 30x faster than without preaggregation.
The two-key index is irrelevant unless there's a preaggregation step.
Adding more and more output columns to the query increases the execution time arithmetically:
100 columns: 00:00:17
200 columns: 00:00:35
400 columns: 00:01:10
800 columns: 00:02:23
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 27, 2019 at 2:43 pm
We're just guess here. Please post the full DDL for the Exampledb.dbo.SourceTable_EF278 table including all constraints and indexes.
It would also be helpful if you if you provided some examples of what the the values in the TimeStamp and Value columns looked like.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply