Creating Clustered Index on View with table containing XML data types Takes Forever and causes Timeouts

  • Creating Clustered Index on View with table containing XML data types Takes Forever and causes Timeouts

    I am trying to create a clustered index on a View of a table that has  an xml datatype. This indexing ran for two days and still did not complete. I tried to leave it running while continuing to use the database, but the SELECT statements where executing too slowly and the DML statements where Timing out. I there a way to control the server/cpu resources used by an indexing process. How can I determine the completion percentage or the indexing process. How can I make indexing the view with the xml data type take less time?

     

    The table definition is displayed below.

     

    CREATE TABLE [dbo].[AuditLogDetails](

    [ID] [int] IDENTITY(1,1) NOT NULL,

    [RecordID] [int] NOT NULL,

    [TableName] [varchar](64) NOT NULL,

    [Modifications] [xml] NOT NULL,

    CONSTRAINT [PK_AuditLogDetails] 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]

     

    The view definition is displayed below.

     

    ALTER VIEW [dbo].[vwAuditLogDetails] WITH SCHEMABINDING

    AS

    SELECT P.ID,D.RecordID, dbo.f_GetModification(D.Modifications,P.ID) AS Modifications

    FROM dbo.AuditLogParent P

    INNER JOIN dbo.AuditLogDetails AS D ON dbo.f_GetIfModificationExist(D.Modifications,P.ID)=1

     

    The definition for UDF f_GetModification

     

    ALTER function [dbo].[f_GetModification]( @Modifications xml,@PID uniqueidentifier )

    returns xml

    with schemabinding

    as

    begin

    declare @pidstr varchar(100)

    SET @pidstr = LOWER(CONVERT(varchar(100), @PID))

    return @Modifications.query('/Modifications/modification[@ID eq sql:variable("@pidstr")]')

    end

     

     

    The definition for UDF f_GetIfModificationExist

     

    ALTER function [dbo].[f_GetIfModificationExist]( @Modifications xml,@PID uniqueidentifier )

    returns Bit

    with schemabinding

    as

    begin

    declare @pidstr varchar(100)

    SET @pidstr = LOWER(CONVERT(varchar(100), @PID))

    return @Modifications.exist('/Modifications/modification[@ID eq sql:variable("@pidstr")]')

    end

     

    The Statement to create the index is below.

     

    CREATE UNIQUE CLUSTERED INDEX [IX_ID_RecordID] ON [dbo].[vwAuditLogDetails]

    (

    [ID] ASC,

    [RecordID] ASC

    )WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

  • Hi Sacha,

    I'd like to know how many rows you have in the table you're trying to index.

    I would suggest creating a copy of the table and inserting perhaps 1 percent of the data from the original table, and attempt the same type of operation.  I'd be interested in seeing the results.

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply