XMLDocuments growing bigger

  • I have a xml table in which it has 10 million records in it . Every day there will be approx 5000 files dumped into the table which is really slow. Can you suggest some best practices to improve the performance?

  • With that many rows now it will take time, but setting up XML indexes can make a HUGE difference. Without seeing how your XML is being stored I can't really offer much more than that. But say you have an XML column that has a typical entry like this:

    CREATE TABLE [dbo].[!Test](

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

    [Col1] [int] NULL,

    [Col2] [nvarchar](50) NULL,

    [Col3] [xml] NULL

    ) ON [PRIMARY]

    GO

    SET IDENTITY_INSERT [dbo].[!Test] ON

    INSERT [dbo].[!Test] ([ID], [Col1], [Col2], [Col3]) VALUES (1, 2345, N'TEST', N'<code attribute="color" value="red" />')

    INSERT [dbo].[!Test] ([ID], [Col1], [Col2], [Col3]) VALUES (2, 4566, N'TEST2', N'<code attribute="color" value="blue" />')

    SET IDENTITY_INSERT [dbo].[!Test] OFF

    use LocalTestDB

    GO

    ALTER TABLE [dbo].[!Test] ADD CONSTRAINT [PK_!Test] PRIMARY KEY CLUSTERED

    ([ID] ASC)

    CREATE PRIMARY XML INDEX [IX_Test_XML]

    ON [dbo].[!Test]([Col3])

    CREATE XML INDEX [IX_Test_XML_Code]

    ON [dbo].[!Test]([Col3])

    USING XML INDEX [IX_Test_XML]

    FOR PATH

    CREATE XML INDEX [IX_Test_attribute]

    ON [dbo].[!Test]([Col3])

    USING XML INDEX [IX_Test_XML]

    FOR PROPERTY

    CREATE XML INDEX [IX_Test_color]

    ON [dbo].[!Test]([Col3])

    USING XML INDEX [IX_Test_XML]

    FOR VALUE

    SELECT TOP 1000 [ID]

    ,[Col1]

    ,[Col2]

    ,[Col3]

    FROM [dbo].[!Test]

    These are like any other indexes in that you may not need all three types or you may need more for additional properties. That will take some testing to see what effect the indexes have on your query plan. Test on a small chunk of that million-row table and when you have the indexes the way you want them they can be applied to the actual data.

     

     

  • Thanks for the reply. I thought of putting up XML Indexes, but the concern is the table is huge it will take a lot of time to create the indexes.. may be like 15-20 hours.

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

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