Sql-Server

驗證統計的重要性?具有自動創建統計資訊的數據庫有效嗎?

  • May 11, 2016

在 SQL Server 2005 上工作,我想使用數據庫引擎優化顧問來幫助我優化我的網路伺服器。

我要做的第一件事是創建一個伺服器端配置文件跟踪並執行大約一個小時。

這是生成的跟踪文件。

當我在 DTA 上使用此文件時,我得到以下建議:

在此處輸入圖像描述

建議翻譯成下面的腳本,評論在那裡,因為我仔細檢查了索引建議。

CREATE STATISTICS [_dta_stat_2108846875_3_6] ON [dbo].[ProductBulletPoint]([LanguageId], [NoteTypeCode])


CREATE NONCLUSTERED INDEX [_dta_index_ProductBulletPoint_39_2108846875__K6_K1_K3_2_4_5_7] ON [dbo].[ProductBulletPoint] 
(
   [NoteTypeCode] ASC,
   [Tier1] ASC,
   [LanguageId] ASC
)
INCLUDE ( [SeasonItemId],
[SortOrder],
[NoteText],
[NoteGroup]) WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]


--SP_HELPINDEX9 'ProductBulletPoint'
-- the index [_dta_index_ProductBulletPoint_39_2108846875__K6_K1_K3_2_4_5_7]  is ok to implement

CREATE NONCLUSTERED INDEX [_dta_index_ProductShipTax_39_745366020__K7_K5_K2_K3_K1_K4_6] ON [dbo].[ProductShipTax] 
(
   [TaxRegionId] ASC,
   [ItemNo] ASC,
   [DateFrom] ASC,
   [DateTo] ASC,
   [ProductShipTaxID] ASC,
   [TaxRate] ASC
)
INCLUDE ( [TaxCode]) WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]


--SP_HELPINDEX9 'ProductShipTax'
-- the index [_dta_index_ProductShipTax_39_745366020__K7_K5_K2_K3_K1_K4_6]



CREATE NONCLUSTERED INDEX [_dta_index_SiteRewriteCache_39_1481368642__K9_K10_2] ON [dbo].[SiteRewriteCache] 
(
   [StartDate] ASC,
   [EndDate] ASC
)
INCLUDE ( [CacheKey]) WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]


--SP_HELPINDEX9 'SiteRewriteCache'
-- the index _dta_index_SiteRewriteCache_39_1481368642__K9_K10_2 is ok to be implemented


CREATE STATISTICS [_dta_stat_89363683_3_2_4] ON [dbo].[ProductClassSegGroupT1]([GroupID], [SegmentID], [Tier1])

CREATE STATISTICS [_dta_stat_89363683_6_2_4] ON [dbo].[ProductClassSegGroupT1]([GenderCode], [SegmentID], [Tier1])

CREATE STATISTICS [_dta_stat_89363683_1_2_3_4_5] ON [dbo].[ProductClassSegGroupT1]([ClassID], [SegmentID], [GroupID], [Tier1], [SortOrder])

CREATE STATISTICS [_dta_stat_89363683_1_4_2] ON [dbo].[ProductClassSegGroupT1]([ClassID], [Tier1], [SegmentID])

CREATE STATISTICS [_dta_stat_473365051_3_4_2_1] ON [dbo].[ProductImages]([Language], [Tier1], [SeasonItemID], [ProductImageID])

CREATE STATISTICS [_dta_stat_473365051_2_1_3] ON [dbo].[ProductImages]([SeasonItemID], [ProductImageID], [Language])

CREATE STATISTICS [_dta_stat_745366020_4_7] ON [dbo].[ProductShipTax]([TaxRate], [TaxRegionId])

CREATE STATISTICS [_dta_stat_745366020_4_5_7_3_2] ON [dbo].[ProductShipTax]([TaxRate], [ItemNo], [TaxRegionId], [DateTo], [DateFrom])

CREATE STATISTICS [_dta_stat_745366020_7_1_4_5_2_3] ON [dbo].[ProductShipTax]([TaxRegionId], [ProductShipTaxID], [TaxRate], [ItemNo], [DateFrom], [DateTo])

CREATE STATISTICS [_dta_stat_745366020_5_3_2_1] ON [dbo].[ProductShipTax]([ItemNo], [DateTo], [DateFrom], [ProductShipTaxID])

CREATE STATISTICS [_dta_stat_745366020_3_7_5] ON [dbo].[ProductShipTax]([DateTo], [TaxRegionId], [ItemNo])

CREATE STATISTICS [_dta_stat_745366020_1_5_2] ON [dbo].[ProductShipTax]([ProductShipTaxID], [ItemNo], [DateFrom])

CREATE STATISTICS [_dta_stat_745366020_2_7] ON [dbo].[ProductShipTax]([DateFrom], [TaxRegionId])

CREATE STATISTICS [_dta_stat_745366020_1_7_5_2] ON [dbo].[ProductShipTax]([ProductShipTaxID], [TaxRegionId], [ItemNo], [DateFrom])

CREATE STATISTICS [_dta_stat_1033367046_6_2_1_8] ON [dbo].[ProductURL]([Tier1], [ClassID], [ProductURLID], [Tier3])

CREATE STATISTICS [_dta_stat_1033367046_8_9_6_2_1_3_4_7] ON [dbo].[ProductURL]([Tier3], [LanguageID], [Tier1], [ClassID], [ProductURLID], [SegmentID], [GroupID], [Tier2])

CREATE STATISTICS [_dta_stat_1033367046_1_3_4_7] ON [dbo].[ProductURL]([ProductURLID], [SegmentID], [GroupID], [Tier2])

CREATE STATISTICS [_dta_stat_1033367046_6_2_1_3_4_7_8] ON [dbo].[ProductURL]([Tier1], [ClassID], [ProductURLID], [SegmentID], [GroupID], [Tier2], [Tier3])

CREATE STATISTICS [_dta_stat_1481368642_10_9] ON [dbo].[SiteRewriteCache]([EndDate], [StartDate])

這是我有問題的數據庫。您可以看到它啟用了自動創建統計資訊和自動更新統計資訊。

在此處輸入圖像描述

問題

  • 為什麼我要創建這麼多統計資訊,因為我的數據庫有自動創建統計資訊?
  • 我如何仔細檢查它建議創建的每個統計數據是否真的有用?

對於索引,我先看看我目前對特定對像有什麼,然後我決定可能改變一個索引,或者創建一個刪除現有的索引,或者創建一個新的索引,這取決於具體情況,但我會如何繼續與統計數據?

為什麼我要創建這麼多統計資訊,因為我的數據庫有自動創建統計資訊?

自動統計只能創建單列統計對象。DTA 建議的統計數據都是多列統計數據,可擷取潛在有用(儘管有限)的相關資訊。

有關詳細資訊,請參閱統計文件

我如何仔細檢查它建議創建的每個統計數據是否真的有用?

以通常的方式。新的統計數據可能會或可能不會改善基數估計、計劃選擇和績效。與任何其他 DTA 建議一樣,在之前和之後進行測試,並且只保留您發現(或期望)有益的更改。

引用自:https://dba.stackexchange.com/questions/137992