Question

I have got a table in sql server 2012 which gets almost 66 million inserts in a week. On which columns should I use indexes?

create TABLE [dbo].[Details](
        [ID] [bigint] IDENTITY(1,1) NOT NULL,
        [WorkflowContentMetricsID] [bigint] not null,
        [ContentType] [nvarchar](1000) NULL,
        [SourceID] [nvarchar](2000) NULL,
        [DestinationID] [nvarchar](2000) NULL,
        [ParentSourceID] [nvarchar](2000) NULL,
        [Title] [nvarchar](max) NULL,
        [Status] [nvarchar](max) NULL,
        [Debug] [nvarchar](max) NULL,
        [Metadata] [nvarchar](max) NULL,
        [StatusCategory] [nvarchar](max) NULL,
        [SangamWorkflowRunID] [nvarchar](1000) NULL,
        [StartDateTime] [nvarchar](1000) NULL,
     CONSTRAINT [PK_WorkflowContentDetails] PRIMARY KEY CLUSTERED 
    (
        [ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

    GO

The query which I use is

SELECT ID
      ,WorkflowContentMetricsID
      ,ContentType
      ,SourceID
      ,DestinationID
      ,ParentSourceID
      ,Title
      ,[Status]
      ,Debug
      ,Metadata
      ,StatusCategory
FROM WorkflowContentDetails
WHERE ContentType NOT IN ('Image' , 'EntityList')
AND SangamWorkflowRunID = @SangamWorkflowRunID
And StatusCategory in (@StatusCategory)

No correct solution

OTHER TIPS

If it is only for insert (as your question states), then do not use indexes on any column. The more the indexes a table has, slower the execution becomes.

The insert statement is the only operation that cannot directly benefit from indexing because it has no WHERE clause.

Indexes do not help with inserting - they hurt because they must be written to as well. If you only ever query the table with the one query provided, create an index just for that query. It should include selective columns. SangamWorkflowRunID, StatusCategory and ContentType appear to be useful here.

More cannot be said with the information provided. I suggest you invest a little time in understanding how indexing works and how it influences both SELECT and DML performance.

For the inserts themselves use a form of the bulk insert facilities SQL Server provides. 66m rows will not take particularly long to insert.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top