I want to Query over 14,000,000 documents stored as XML field in SQL Server.
I’ve generated 1,000,000 rows in data base to test now, but simple select with no where condition takes about 3 minutes. I also applied XML Indexing but it’s still not acceptable in performance. Similar scenario takes 19 Sec for similar table which have all fields as typed.
Here is my typed table:
CREATE TABLE [dbo].[Fields] (
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Title] NCHAR (10) NOT NULL,
[Duration] INT NOT NULL,
[Cost] MONEY NOT NULL,
[Consignee] BIGINT NOT NULL,
[Date] DATETIME NOT NULL,
[TariffId] BIGINT NOT NULL,
[InvoiceType] NCHAR (10) NOT NULL,
[IsPayed] BIT NOT NULL
);
and this one is the one XML sample:
<Invoice>
<Id>1</Id>
<Title>title</Title>
<Duration>726643700</Duration>
<Cost>312118909727165.6133</Cost>
<Consignee>3120910928797722624</Consignee>
<Date>4543-07-16T01:40:29.623</Date>
<TariffId>3120910928797722624</TariffId>
<InvoiceType>InvoiceType</InvoiceType>
<IsPayed>1</IsPayed>
</Invoice>
These are indexes I applied:
CREATE XML INDEX idx_xCol_Path on [dbo].[XML] (InvoiceItem)
USING XML INDEX idx_xCol FOR PATH
CREATE XML INDEX idx_xCol_Value on [dbo].[XML] (InvoiceItem)
USING XML INDEX idx_xCol FOR VALUE
My vary tests made my decision change. Xml is great for about 1-2 million records. In my case, the application life time should be more that 3 years with document production velocity.
So I tried to use tables instead of xml fields. Other possible solution could be a single record, but there was xml document size limit. As I monitor the performance vs record numbers, I found out it dives after a million records. Also, Index files on SQL grow up was not acceptable with this scale.