Polybase : Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim

Hervé 20 Reputation points
2024-03-07T10:06:54.45+00:00

Hello

We encountered the following error while reading data from an external table SQL Error Information: SrvrMsgState: 52, SrvrSeverity: 13, Error <1>: ErrorMsg: [Microsoft][ODBC Driver 17 for SQL Server ][SQL Server]The Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

We tried using the WITH(NOLOCK) clause but it returned the following error:

Msg 46915, Level 16, State 1, Line 2 Table hints are not supported on queries that reference external tables.

After searching, we couldn't find how to change the default isolation level by modifying the CONNECTION_OPTIONS property when creating the external source.
CREATE AN EXTERNAL DATA SOURCE MyDataBase WITH ( LOCATION = 'sqlserver://XXXXXXX' , CONNECTION_OPTIONS = ' ????? , TITLE = XXXXXXCredential );
Thank you in advance.
Best regards

Developer technologies | Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 78,311 Reputation points Volunteer Moderator
    2024-03-07T18:14:35.2433333+00:00

    you can not set the isolation level in the connect string. If you changed your target sqlserver to snapshot isolation you will have fewer blocking issues.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 122.4K Reputation points MVP Volunteer Moderator
    2024-03-07T22:50:31.5066667+00:00

    Be glad that NOLOCK was not accepted. NOLOCK can give you incorrect results, particularly when there are concurrent activity. Incorrect results are a lot worse than deadlocks.

    The easy way out, as Bruce says, is to set the remote database in READ_COMMITTED_SNAPSHOT, although this may not always be safe.

    The other alternative is to analyse the deadlock and see what can be done to resolve it. Here is a query to view deadlock information on a server:

    ; WITH CTE AS (
      SELECT CAST(event_data AS xml) AS xml, timestamp_utc
      FROM sys.fn_xe_file_target_read_file(
         N'system_health*.xel', DEFAULT, DEFAULT, DEFAULT)
      WHERE object_name = 'xml_deadlock_report'
    )
    SELECT xml.query('/event/data[1]/value[1]/deadlock[1]'), timestamp_utc
    FROM   CTE
    ORDER BY timestamp_utc DESC
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.