Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Xml index Expand / Collapse
Author
Message
Posted Thursday, May 2, 2013 11:49 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 6:04 AM
Points: 269, Visits: 1,731
I have a table with following column.(I have directly give the create table command)
CREATE TABLE [dbo].[BalanceTable](
[AccountID] [int] NOT NULL,
[Type] [varchar](10) NULL,
[Date] [date] NOT NULL,
[Balance] [decimal](15, 2) NULL,
[TRansactionDr] [decimal](15, 2) NULL,
[TRansactionCr] [decimal](15, 2) NULL,
[daily_Balance] [xml] NULL,
CONSTRAINT [PK_BalanceTable] PRIMARY KEY CLUSTERED
(
[AccountID] ASC,
[Date] 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

I have a xml query which updates this table. But it works slowly and take some seconds. I want to speed it up. So i was try to use xml index.So in this case which index i should use? Primary? secondary(in that i have path,value and property)? So which will be better to use which will reduce time required for execution.
Below is query

Update BalanceTable set [daily_balance].modify('replace value of (/Root/Row[date=''2011-03-23'']/Balance/text())[1] with (/Root/Row[date=''2011-03-23'']/ Balance)[1] +1') where [AccountID]=26 and [Date]='31-Mar-2011' and [daily_balance].exist('/Root/Row[date=''2011-03-23'']')=1;

Also here is sample of xml column

<Root>
<Row>
<Rowid>0</Rowid>
<date>2011-01-23</date>
<Balance>0.0E0</Balance>
<TRansactionDr>0.0E0</TRansactionDr>
<TRansactionCr>0.0E0</TRansactionCr>
</Row>
<Maxrowid>0</Maxrowid>
<Row>
<Rowid>0</Rowid>
<date>2011-01-31</date>
<Balance>123</Balance>
<TRansactionDr>123</TRansactionDr>
<TRansactionCr>0.0E0</TRansactionCr>
</Row>
</Root>

So please give me suggestions
Post #1449054
Posted Friday, May 3, 2013 2:58 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:19 AM
Points: 2,963, Visits: 2,982
Hi,

Because you use exist() you should create FOR PATH type xml index.

Regards
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1449086
Posted Friday, May 3, 2013 3:15 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 6:04 AM
Points: 269, Visits: 1,731
Ok. But while creating PATH type index is there needed to specify the path which i use?
I don't know much about xml indexing. But for other datatypes there is option of filtered index where i can specify the condition.
So is there any option in xml also? If not then for which path it will create index for xml column?
Post #1449093
Posted Friday, May 3, 2013 3:36 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:19 AM
Points: 2,963, Visits: 2,982
IT researcher (5/3/2013)
Ok. But while creating PATH type index is there needed to specify the path which i use?
I don't know much about xml indexing. But for other datatypes there is option of filtered index where i can specify the condition.
So is there any option in xml also? If not then for which path it will create index for xml column?


No, you don't need to specify any paths

Can you try this?

create primary xml index PXML_daily_Balance on BalanceTable(daily_Balance)
create xml index [SECXMl_daily_Balance_path] on BalanceTable(daily_Balance)
using xml index [PXML_daily_Balance] for path

Regards,
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1449100
Posted Friday, May 3, 2013 5:48 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 6:04 AM
Points: 269, Visits: 1,731
Whether i can use selective xml index? Does it available in sql server 2008 r2 express?
Post #1449151
Posted Friday, May 3, 2013 6:43 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:19 AM
Points: 2,963, Visits: 2,982
IT researcher (5/3/2013)
Whether i can use selective xml index? Does it available in sql server 2008 r2 express?


It's available from sql server 2012.




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1449169
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse