Hi Experts,
I am getting below error while executing the stored procedure.
The query has been canceled because the estimated cost of this query (3258) exceeds the configured threshold of 2500. Contact the system administrator.
I am importing the XML into the table. Actually, I am uploading CSV contacts in my application & then push the XML to sql server. Here, I extract the contacts using xpath query, & save into a table. In my local machine, this code works fine while I
upload this code on production server, it raises the above error. below is the sample code which I am using:
INSERT INTO @TempTable(FullName, FirstName, LastName, Email, DateOfBirth, CountryCode)
SELECT FullName = T.Item.query('fullname').value('.', 'VARCHAR(256)'),
FirstName = T.Item.query('firstname').value('.', 'VARCHAR(256)'),
LastName = T.Item.query('lastname').value('.', 'VARCHAR(256)'),
Email = T.Item.query('email').value('.', 'VARCHAR(256)'),
DOB = CASE WHEN T.Item.query('dateofbirth').value('.', 'VARCHAR(10)') = '' THEN NULL
ELSE CONVERT(DATE, T.Item.query('dateofbirth').value('.', 'VARCHAR(10)'), 103)
END,
CC = T.Item.query('country').value('.', 'CHAR(2)')
FROM @xmlData.nodes('contacts/contact') AS T(Item);
above code works fine & takes only few milliseconds on my local system but throws an error on production server.
I have tried to search the reason & found that this error is due to long execution time. so, either I will have to increase the query governor execution time or I will have to optimize the query.
But I am not able to understand what can I do to optimize this query. This is basic XQuery syntax. Please guide me how can I fix this issue ?