SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


table valued function xml reader high cost


table valued function xml reader high cost

Author
Message
kbhanu15
kbhanu15
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1833 Visits: 344
Hi All,

I have a xml and i am inserting data into one temp table from xml.

this cost is very high.can u please give your valuable suggestions to reduce this xml reader cost.

Please find the actual execution plan.

Original query:


---XML
DECLARE @entityIds XML
SET @entityIds =N'<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<int>112350</int>
<int>100886642</int>
</ArrayOfInt>'


---INSERT INTO TEMP TABLE
SELECT Tbl.Col.value('.', 'int') AS val
into #entityIdList
FROM @entityIds.nodes('/ArrayOfInt/int') Tbl(Col)

---SELECT DATA FROM TEMP TABLE
select * FROM #entityIdList
Attachments
exec plan.sqlplan (38 views, 32.00 KB)
more details.png (43 views, 77.00 KB)
kbhanu15
kbhanu15
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1833 Visits: 344
i used like this query hint now i got some performance improvement.
please let me know is it valid or not ?


---XML
DECLARE @entityIds XML
SET @entityIds =N'<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<int>112350</int>
<int>100886642</int>
</ArrayOfInt>'


---INSERT INTO TEMP TABLE
INSERT INTO #entityIdList
SELECT Tbl.Col.value('.', 'int') AS val
FROM @entityIds.nodes('/ArrayOfInt/int') Tbl(Col)
OPTION ( OPTIMIZE FOR ( @entityIds = null) )

---SELECT DATA FROM TEMP TABLE
select * FROM #entityIdList
kbhanu15
kbhanu15
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1833 Visits: 344
please find the code in detail

IF OBJECT_ID('tempdb..#entityIdList') IS NOT NULL
drop TABLE #entityIdList

create TABLE #entityIdList
(
val INT
)

---XML
DECLARE @entityIds XML
SET @entityIds =N'<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<int>112350</int>
<int>100886642</int>
</ArrayOfInt>'


---INSERT INTO TEMP TABLE
INSERT INTO #entityIdList
SELECT Tbl.Col.value('.', 'int') AS val
FROM @entityIds.nodes('/ArrayOfInt/int') Tbl(Col)
OPTION ( OPTIMIZE FOR ( @entityIds = null) )

---SELECT DATA FROM TEMP TABLE
select * FROM #entityIdList
lnardozi 61862
lnardozi 61862
Old Hand
Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)Old Hand (381 reputation)

Group: General Forum Members
Points: 381 Visits: 617
For some reason you don't need the hint if you do it like this.


DECLARE @entityIds XML
SET @entityIds =N'<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<int>112350</int>
<int>100886642</int>
</ArrayOfInt>'


---INSERT INTO TEMP TABLE
SELECT Tbl.Col.value('.', 'int') AS val
into #entityIdList
FROM @entityIds.nodes('/ArrayOfInt/int/text()') Tbl(Col)
--OPTION ( OPTIMIZE FOR ( @entityIds = null ) )
---SELECT DATA FROM TEMP TABLE
select * FROM #entityIdList

drop table #entityIdList


kbhanu15
kbhanu15
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1833 Visits: 344
HI All,

Thank you for your help.

but i need to explain this change.

FROM @entityIds.nodes('/ArrayOfInt/int/text()') Tbl(Col)

can you please explain me why we change
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search