Note that there are some explanatory texts on larger screens.

plurals
  1. POClustered and covering index ignored on delete statement. Table scan occurs
    primarykey
    data
    text
    <p><strong>Why would SQL Server 2005 find it more efficient to perform a table scan instead of using the available clustered index on the primary key (and only the primary key)?</strong> </p> <p><strong>DISCLAIMER</strong>: There is <em>also</em> a non-clustered, non-unique index on the primary key with no included columns. This is baffling to me and we've had a good office chuckle already. If this index ends up being the problem, then we know who to shoot. Unfortunately, it's a production site and I can't just rip it out but will make plans to do so if necessary. </p> <p>Maybe the problem is not the mentally deficient contrary index, however...</p> <p>According to FogLight PASS the following statement has been causing a scan on a table with ~10 million rows about 600 times an hour when we delete a row by the primary key:</p> <pre><code>DELETE FROM SomeBigTable WHERE ID = @ID </code></pre> <p>The table DDL:</p> <pre><code>CREATE TABLE [SomeBigTable] ( [ID] [int] NOT NULL, [FullTextIndexTime] [timestamp] NOT NULL, [FullTextSearchText] [varchar] (max) NOT NULL, CONSTRAINT [PK_ID] PRIMARY KEY CLUSTERED ( [ID] ASC ) ) -- ... ON PRIMARY </code></pre> <p>The clustered index constraint in detail:</p> <pre><code>ADD CONSTRAINT [PK_ID] PRIMARY KEY CLUSTERED ( [ID] 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 = 75 ON PRIMARY </code></pre> <p>The non-unique, non-clustered index on the same table:</p> <pre><code>CREATE NONCLUSTERED INDEX [IX_SomeBigTable_ID] ON [SomeBigTable] ( [ID] 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 = 98 ON PRIMARY </code></pre> <p>There is <em>also</em> a foreign key constraint on the [ID] column pointing to an equally large table.</p> <p>The 600 table scans are about ~4% of the total delete operations per hour on this table using the same statement. So, not all executions of this statement cause a table scan.</p> <p>It goes without saying, but saying it anyway...this is a lot of nasty I/O that I'd like to send packing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload