I am working with enhancing performance on an old stored procedure. Currently it's getting single node XML parameter passed from another stored procedure. The XML is then used in a cross apply. I'm wondering if the X-Query in the CROSS APPY is pulling out the value row by row, or if it is parsed beforehand. Would it be less overhead for me to pass the list as a UDT instead of XML

This is the code that generates the XML

SELECT @NewRunBatchProcessSteps = (
    SELECT Tracking.NewPrimaryKey RunBatchProcessStepId
    FROM @RunBatchProcessStep AS RunBatchProcessStep
        INNER JOIN @RunBatchProcessNew Tracking ON RunBatchProcessStep.RunBatchProcessStepId = Tracking.OldPrimaryKey
    FOR XML PATH('RunBatchProcessStep'), ROOT ('RunBatchProcessSteps')
)

Here's how it's used.

SELECT SomeFields
FROM RunBatchProcessStep 
CROSS APPLY @NewRunBatchProcessSteps.nodes('/RunBatchProcessSteps/RunBatchProcessStep') RunBatchProcessStepsXML(ref)
INNER JOIN BatchProcessStep btp ON RunBatchProcessStep.BatchProcessStepId = btp.BatchProcessStepId
INNER JOIN Module m ON m.ModuleCode = btp.ModuleCode
WHERE RunBatchProcessStep.RunBatchProcessStepId = ref.value('RunBatchProcessStepId[1]', 'INT')

If I was to take @NewRunBatchProcessSteps and turn it into a single column UDT and then Inner Join to it, should I see a performance improvement?

有帮助吗?

解决方案

It's based on your data count. If you pass more number of data means, you can use UDT otherwise you can use XML. Because XML parsing takes more time when you pass more no.of data. So it's based on your requirement.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top