Hola a todos nuevamente, tengo una consulta, una tabla de mas de 1 millon de registros, tengo que generar registros y actualizar, cuando actualizo hago el siguiente where, pero en la etapa inicial del sistema, era muy rapido, pero ahora demora, la pregunta es si es recomendable generar indices por cada campo que esta en lista o un indice con todas las columnas?, espero sus comentarios, gracias. Ya lo probe en el optimizador de indices y no me aconseja nuevos indices. where OrdCort_codi = @OrdCort_codi and Esti_codi = @esti_codi and surt_codi = @surt_codi and Colo_codi = @colo_codi and Prendes_codi = @Prendes_codi and Cenc_codi = @Cenc_codi and Bloq_codi = @Bloq_codi and Fami_codi = @Fami_codi and Oper_codi = @Oper_codi and Paqu_codi = @Paqu_codi and Tall_codi = @Tall_codi
Estás actualizando estadÃsticas y defragmentando Ãndices? Luis Martin Moderator SQL-Server-Performance.com One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important Bertrand Russell All postings are provided “AS IS†with no warranties for accuracy.
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tickets]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Tickets] GO CREATE TABLE [dbo].[Tickets] ( [OrdeTrab_codi] [char] (10) COLLATE Modern_Spanish_CI_AS NOT NULL , [OrdCort_codi] [char] (10) COLLATE Modern_Spanish_CI_AS NOT NULL , [Esti_codi] [char] (30) COLLATE Modern_Spanish_CI_AS NOT NULL , [Surt_codi] [int] NOT NULL , [Prendes_codi] [char] (35) COLLATE Modern_Spanish_CI_AS NOT NULL , [Colo_codi] [char] (4) COLLATE Modern_Spanish_CI_AS NOT NULL , [Tall_codi] [char] (3) COLLATE Modern_Spanish_CI_AS NOT NULL , [Paqu_codi] [int] NOT NULL , [Cant_Paqu] [numeric](20, 0) NOT NULL , [Tick_Codi] [char] (15) COLLATE Modern_Spanish_CI_AS NOT NULL , [Tick_Leid] [int] NOT NULL , [Secu_Oper] [int] NOT NULL , [Secu_Bloq] [int] NOT NULL , [Cenc_codi] [char] (3) COLLATE Modern_Spanish_CI_AS NOT NULL , [Bloq_codi] [int] NOT NULL , [Fami_codi] [int] NOT NULL , [Oper_codi] [int] NOT NULL , [Estu_codi] [int] NOT NULL , [Tick_Tstd] [numeric](20, 6) NOT NULL , [Tick_Item] [int] NOT NULL , [Tick_Fech] [datetime] NULL , [Tick_Year] [numeric](4, 0) NULL , [Tick_Sema] [numeric](2, 0) NULL , [Tick_Ndia] [numeric](2, 0) NULL , [Lectu_Id] [int] NULL , [Line_codi] [int] NULL , [Obre_codi] [char] (10) COLLATE Modern_Spanish_CI_AS NULL , [Tick_Feri] [int] NULL , [Tick_Dest] [int] NULL , [Tick_Plant] [int] NULL , [Tick_HNEx] [int] NULL , [Tick_Cerr] [int] NOT NULL , [Tick_Proc] [int] NOT NULL , [Tick_Elim] [int] NOT NULL , [TickCabe_Codi] [char] (15) COLLATE Modern_Spanish_CI_AS NULL , [Tick_UserCrea] [int] NOT NULL , [Tick_FechCrea] [datetime] NOT NULL , [Tick_UserModi] [int] NOT NULL , [Tick_FechModi] [datetime] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[Tickets] WITH NOCHECK ADD CONSTRAINT [PK_Tickets] PRIMARY KEY CLUSTERED ( [Tick_Codi] ) WITH FILLFACTOR = 90 ON [PRIMARY] GO CREATE INDEX [IX_Tickets] ON [dbo].[Tickets]([OrdCort_codi]) WITH FILLFACTOR = 90 ON [PRIMARY] GO CREATE INDEX [IX_Tickets_1] ON [dbo].[Tickets]([Esti_codi], [Surt_codi], [Prendes_codi], [Colo_codi], [Tall_codi]) WITH FILLFACTOR = 90 ON [PRIMARY] GO CREATE INDEX [IX_Tickets_2] ON [dbo].[Tickets]([OrdeTrab_codi]) WITH FILLFACTOR = 90 ON [PRIMARY] GO CREATE INDEX [IX_Tickets_3] ON [dbo].[Tickets]([Tick_Fech]) WITH FILLFACTOR = 90 ON [PRIMARY] GO CREATE INDEX [IX_Tickets_4] ON [dbo].[Tickets]([Obre_codi]) ON [PRIMARY] GO
Mira, si la tarea fuera la de insertar muchos registros en una tabla que con más de 1 millón de registros, te recomendarÃa que elimines todos lo Ãndices antes de la insercción y los vuelvas a crear después, para mantener la performance en las consultas. Ahora si la tarea es la de actualizar (no insertar), no veo otra alternativa que mejorar el hardware. FÃjate si en el momento de actualizar es necesario lockear los datos, porque si asà no lo fuera, podrÃas utilizar la opción NOLOCK (FÃjate en el Select de los libros). Esto acelerarÃa en algo el proceso. Luis Martin Moderator SQL-Server-Performance.com One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important Bertrand Russell All postings are provided “AS IS†with no warranties for accuracy.