Eu tenho uma tabela com cerca de 7 milhões de registros. A fragmentação do índice foi de cerca de 90 .
Eu tento reconstruir o índice para todos os índices. e funciona bem, mas após a fragmentação do trabalho noturno para um none cluster index
crescimento para 30 . todas as noites eu trunco esta tabela e insiro um novo registro nela e atualizo alguma coluna (índice não clusterizado (não a coluna que eu mencionei)). não sei por que a fragmentação para esse índice( IX_Customer_Code
) cresce rápido. a carga de trabalho na tabela:
1- todas as noites truncadas. 2-inserir cerca de 7.000.000 registros. 3- atualizar Customer_Key
(em inserir fica nulo).
Eu tenho problemas comIX_CustomerCode
name index_type_desc page_count
IX_CustomerCode NONCLUSTERED INDEX 17,323
IX_Customer_Key NONCLUSTERED INDEX 15,608
Ix_Date NONCLUSTERED INDEX 15,561
PK_MDT_Customer_Order_Debit_Date_Infos_Tmp CLUSTERED INDEX 436,675
Estrutura da mesa:
CREATE TABLE [dbo].[MDT_Customer_Order_Debit_Date_Infos](
[OrderDebit_SeqID] [bigint] IDENTITY(1,1) NOT NULL,
[Date_ID] [int] NOT NULL,
[Dist_Zone_Code] [int] NULL,
[Branch_Code] [int] NULL,
[Dist_Area_Code] [int] NULL,
[Dist_Path_Code] [int] NULL,
[Sale_Zone_Code] [int] NULL,
[Region_Code] [int] NULL,
[Office_Code] [int] NULL,
[Area_Code] [int] NULL,
[Path_Code] [int] NULL,
[Visitor_Code] [int] NULL,
[Customer_Code] [int] NULL,
[Customer_Master_Code] [varchar](12) NULL,
[Order_Office_Code] [int] NOT NULL,
[Order_No] [varchar](10) NOT NULL,
[Factor_No] [varchar](10) NULL,
[Order_Status] [tinyint] NULL,
[Sub_Order_Type] [int] NULL,
[Payment_Type] [tinyint] NULL,
[Order_Type] [tinyint] NULL,
[Return_Reason_Code] [int] NULL,
[Order_Price] [numeric](18, 0) NULL,
[PromotionActual_Price] [numeric](18, 0) NULL,
[Order_DutyPlusTax] [numeric](18, 0) NULL,
[ReturnPromotionActual_Price] [numeric](18, 0) NULL,
[Return_Discount] [numeric](18, 0) NULL,
[PromotionDiscount_Price] [numeric](18, 0) NULL,
[Discount] [numeric](18, 0) NULL,
[Calc_Discount] [numeric](18, 0) NULL,
[ReturnOrder_Price] [numeric](18, 0) NULL,
[Return_DutyPlusTax] [numeric](18, 0) NULL,
[Cash_AvgAge] [numeric](18, 2) NULL,
[Check_AvgAge] [numeric](18, 2) NULL,
[Indirect_AvgAge] [numeric](18, 2) NULL,
[Money_Amount] [numeric](18, 0) NULL,
[Indirect_Amount] [numeric](18, 0) NULL,
[Check_Amount] [numeric](18, 0) NULL,
[ReturnCheck_Amount] [numeric](18, 0) NULL,
[RetChqSettle_Cash] [numeric](18, 0) NULL,
[RetChqSettle_Check] [numeric](18, 0) NULL,
[RemainCheck_Debit] [numeric](18, 0) NULL,
[Order_Payable] [numeric](18, 0) NULL,
[Order_Debit] [numeric](18, 0) NULL,
[OrderRemain_ReturnCheck] [numeric](18, 0) NULL,
[RealRemain_Debit] [numeric](18, 0) NULL,
[RealRemain_Check] [numeric](18, 0) NULL,
[Debit_Age] [numeric](18, 2) NULL,
[Payment_Age] [numeric](18, 2) NULL,
[Factor_Date] [int] NULL,
[Order_Date] [int] NULL,
[Visit_Date] [int] NULL,
[Give_Date] [int] NULL,
[Office_Key] [int] NULL,
[Customer_Key] [int] NULL,
[During_Check_Amount] [numeric](18, 0) NULL,
[Collected_Check_Amount] [numeric](18, 0) NULL,
[Dist_Branch_Key] [int] NULL,
[AllCheck_AvgAge] [numeric](18, 2) NULL,
[Cheque_Age] [int] NULL,
[Sale_Remain_Debit] [numeric](18, 0) NULL,
[Dist_Remain_Debit] [numeric](18, 0) NULL,
[HandMoney_Amount] [numeric](18, 0) NULL,
[AllCheck_Amount] [numeric](18, 0) NULL,
[Indirect_Discount_Amount] [numeric](18, 0) NULL,
[PosMoney_Amount] [numeric](18, 0) NULL,
[Portfolio_Code] [int] NULL,
[Portfolio_Set_Code] [int] NULL,
[Portfolio_Type] [tinyint] NULL,
[Company_id] [smallint] NULL,
CONSTRAINT [PK_MDT_Customer_Order_Debit_Date_Infos_Tmp] PRIMARY KEY CLUSTERED
(
[OrderDebit_SeqID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IX_Customer_Key] ON [dbo].[MDT_Customer_Order_Debit_Date_Infos]
(
[Customer_Key] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object: Index [IX_CustomerCode] Script Date: 1/20/2014 6:02:52 PM ******/
CREATE NONCLUSTERED INDEX [IX_CustomerCode] ON [dbo].[MDT_Customer_Order_Debit_Date_Infos]
(
[Customer_Code] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object: Index [Ix_Date] Script Date: 1/20/2014 6:02:59 PM ******/
CREATE NONCLUSTERED INDEX [Ix_Date] ON [dbo].[MDT_Customer_Order_Debit_Date_Infos]
(
[Date_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
/****** Object: Index [PK_MDT_Customer_Order_Debit_Date_Infos_Tmp] Script Date: 1/20/2014 6:03:07 PM ******/
ALTER TABLE [dbo].[MDT_Customer_Order_Debit_Date_Infos] ADD CONSTRAINT [PK_MDT_Customer_Order_Debit_Date_Infos_Tmp] PRIMARY KEY CLUSTERED
(
[OrderDebit_SeqID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO
O índice não clusterizado provavelmente tem uma ordem diferente da tabela base e, portanto, as inserções/atualizações nessa coluna fragmentarão o índice.
FILLFACTOR
(ePAD_INDEX
) as configurações só se aplicam quando o índice é reconstruído, não durante as operações normais.O que eu sugeriria é descartar todos os índices não clusterizados na tabela antes de carregar os novos dados e, em seguida, recriar os índices depois de terminar de mexer nos dados que os afetariam.
Se a fragmentação é ou não um problema no seu caso, é discutível. Embora a tabela seja bastante ampla, eliminar a fragmentação do índice não clusterizado é uma preocupação apenas se você precisar varrer esse índice do disco, o que não acontecerá se o índice já estiver na memória. O índice não clusterizado é muito pequeno em comparação com a tabela. Você precisaria descobrir em seu sistema se há uma diferença mensurável no desempenho da consulta antes/depois de reconstruir o índice, mas como mencionei acima, você pode estar mais à frente para descartar/recriar o índice de qualquer maneira, o que eliminaria a fragmentação e também permitem que você use 100%
FILLFACTOR
.Você só precisa se preocupar com a fragmentação quando todos esses fatores forem verdadeiros: