I have a 2.5 billion record table that i broke out into a table for all of 2013. One table for all of 2014 then a table per monthfrom 1/1/2015' till 12/31/2016. So there are 36 individual tables w/ a constraint on the "DateOfData" coulmn which is how the data is separated.The primay key is on 5 columns and dateofdata is the third column in the key. I'm using sql server 2014 standard. I created a partitioned view on top of all the tables. I have a query that appears to be trying to read from all 26 tables even though i'm only selecting a handfull of dates from the past weeknotice the below--print 'start - '+cast(getdate() as varchar)IF Object_id('tempdb..#dates') IS NOT NULL DROP TABLE #datesDECLARE @entdt DATETIME;DECLARE @startdate DATETIME;SET @startdate = Dateadd(dd, -8, Getdate())SET @entdt = Getdate()DECLARE @dcnt INT;WITH DateList AS (SELECT Cast(@startdate AS DATETIME) datevalue UNION ALL SELECT datevalue + 1 FROM DateList WHERE datevalue + 1 < CONVERT(VARCHAR(15), @entdt, 101))SELECT *INTO #datesFROM DateListOPTION (maxrecursion 0);SELECT *FROM #datesPRINT 'del - ' + Cast(Getdate() AS VARCHAR)SET statistics io ONSELECT [clientid], [dateofdata], [dimension line_item_id], [dimension creative_id], Sum([impressions]) imp, Sum([clicks]) clkfrom [dbo].vw_report_history rh(nolock) where dateofdata in ('9/1/2016','9/6/2016')GROUP BY [clientid], [dimension line_item_id], [dateofdata], [dimension creative_id]-----io stats--------------Table 'testtable_201509'. Scan count 1, logical reads 61, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table '#dates______________________________________________________________________________________________________________00000002BF17'. Scan count 1, logical reads 1, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.--end io stats -------------------------query twosELECT [clientid], [dateofdata], [dimension line_item_id], [dimension creative_id], Sum([impressions]) imp, Sum([clicks]) clkFROM (SELECT DISTINCT datevalue dt FROM #dates) dt JOIN [dbo].vw_report_history rh(nolock) ON rh.dateofdata = dt.dtGROUP BY [clientid], [dimension line_item_id], [dateofdata], [dimension creative_id]-------------io stats ---------------------Table 'DFP_Reports_History_2013'. Scan count 33, logical reads 3592388, physical reads 6, read-ahead reads 3580434, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_2014'. Scan count 33, logical reads 9350518, physical reads 16, read-ahead reads 9306283, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201501'. Scan count 33, logical reads 784547, physical reads 3, read-ahead reads 778613, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201502'. Scan count 33, logical reads 690363, physical reads 3, read-ahead reads 684032, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201503'. Scan count 33, logical reads 1009663, physical reads 8, read-ahead reads 1003467, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201504'. Scan count 33, logical reads 1069080, physical reads 3, read-ahead reads 1061425, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201505'. Scan count 33, logical reads 1200269, physical reads 3, read-ahead reads 1192159, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201506'. Scan count 33, logical reads 1174801, physical reads 5, read-ahead reads 1166932, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201507'. Scan count 33, logical reads 1448145, physical reads 4, read-ahead reads 1440241, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201508'. Scan count 33, logical reads 2727251, physical reads 7, read-ahead reads 2709691, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201509'. Scan count 33, logical reads 2799816, physical reads 15, read-ahead reads 2782194, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201510'. Scan count 33, logical reads 2336149, physical reads 4, read-ahead reads 2325155, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201511'. Scan count 33, logical reads 2933287, physical reads 6, read-ahead reads 2918749, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201512'. Scan count 33, logical reads 3129165, physical reads 9, read-ahead reads 3114056, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201601'. Scan count 33, logical reads 1857644, physical reads 4, read-ahead reads 1849663, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201602'. Scan count 33, logical reads 1751051, physical reads 11, read-ahead reads 1738872, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201603'. Scan count 33, logical reads 1999681, physical reads 6, read-ahead reads 1991852, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201604'. Scan count 33, logical reads 1843576, physical reads 78, read-ahead reads 1830819, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201605'. Scan count 33, logical reads 2132316, physical reads 8, read-ahead reads 2125305, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201606'. Scan count 33, logical reads 2127417, physical reads 10, read-ahead reads 2114634, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201607'. Scan count 33, logical reads 1812176, physical reads 3, read-ahead reads 1801911, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201608'. Scan count 33, logical reads 1929416, physical reads 3, read-ahead reads 1920810, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201609'. Scan count 33, logical reads 114150, physical reads 3, read-ahead reads 112568, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201610'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201611'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.Table 'DFP_Reports_History_201612'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
↧