Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Performance - Updating self referenced table

Author  Topic 

ma.voice
Starting Member

12 Posts

Posted - 2008-10-06 : 06:06:51
Query Performance - Updating self referenced table with XML data type columns

Hi,

To give you a better understanding, I am just trying to create a replica of my situation, so kindly ignore any syntax errors:

In the following temporary table, i have inserted 1000 employee ids, based on some previous different selections: XML columns are null at the moment

create table #tmpEmpXML
(
empid uniqueidentifier,
col_xml1 xml,
col_xml2 xml,
col_xml3 xml,
col_xml4 xml
)


Now i am updating the xml columns of same table with co-related sub-queries.

UPDATE tmpTBL
SET
col_xml1 = (SELECT column_1, column_2, column_3, column_4, column_5
FROM department_hisotry dhist
inner join dept
on dhist.dept_id = dept.dept_id
where emp_id = tmpTBL.emp_id
FOR XML PATH('emp_dep_history'), TYPE),
col_xml2 = (SELECT column_1, column_2, column_3, column_4, column_5
FROM salary_hisotry shist
inner join pay_roll
on shist.emp_id = pay_roll.emp_id
where emp_id = tmpTBL.emp_id
FOR XML PATH('emp_sal_history'), TYPE),
col_xml3 = (SELECT column_1, column_2, column_3, column_4, column_5
FROM transfer_hisotry thist
where emp_id = tmpTBL.emp_id
FOR XML PATH('emp_transfer_history'), TYPE),
col_xml4 = (SELECT column_1, column_2, column_3, column_4, column_5
FROM sales_hisotry sale_hist
where emp_id = tmpTBL.emp_id
FOR XML PATH('emp_sales_history'), TYPE)
FROM
#tmpEmpXML tmpTBL


After this update, I am wrapping this whole temporary table along with updated xmls, into a single output XML. This output XML will be used in the subsequent number of related operations on that XML which is already very well define and cannot be changed at this stage.


In my situation, there are number of other complex joins involved in the inner queries. All relevant key and non-key indexes are already there.

According to the database tuning advisor, this UPDATE code is taking almost 85% of whole SP execution time which is 40-55 seconds, depends on data in tempTable


NOW QUESTION is :- What are possibilities OR any check-list OR ways to improve the performance (speed-up things) and reduce this processing time ?

Cheers

Silent Voice
Bill Gates, MVP

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-06 : 08:33:45
Database tuing advisor?
Not the "Include actual execution plan"?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

ma.voice
Starting Member

12 Posts

Posted - 2008-10-09 : 07:10:19
Already tried DBTA and as i mentioned earlier, necessary indexes are there

I looking for any other best practices in your mind ?

Cheers

Silent Voice
Bill Gates, MVP
Go to Top of Page
   

- Advertisement -