1

We have a large ProductOrders table with many rows, and plan to update it. The table has range of ProductType Ids from 1-1000.

Table has around 2 million rows, 15 columns. Common ProductOrders table: ProductOrderId, ProductId, ProductTypeid, ManufacturerId, OrderDate, etc, indexes are placed properly on foreign keys and common queries.

Two options are proposed to update the table,

  1. Setup 10,000+ multiple queries (grouped by range of Product TypeIds) which are sent out in Parallel, and update the ProductOrders Table all at once.

  2. Or the second proposition, is using following method. Update them sequentially proposed here to avoid locking up the whole table. https://stackoverflow.com/a/35931214/12425844

I would assume option 1) having multiple update queries can lead to multiple Writer-Writer Deadlocks.

Is it safe to have multiple queries sent in parallel? Which option is best practice? Additionally, thoughts it best practice to let Sql automatically conduct DDL items in parallel with configured Maxdop setting, rather than user attempting.

https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-max-degree-of-parallelism-server-configuration-option?view=sql-server-ver15

first option is being proposed by our Application software team .

Currently using AzureSQl.

asked Aug 26, 2020 at 15:59
7
  • Can you share the relevant DDL + any indexes that may be present? Commented Aug 26, 2020 at 16:03
  • "Placed properly" doesn't exactly help here - is there an index with "ProductTypeId" as its first column? What column(s) are you updating and why? Commented Aug 26, 2020 at 16:08
  • we are updating productStatusId, regionid, updateDate, and yes, there is index on ProductTypeId, ProductOrderId is primary key Commented Aug 26, 2020 at 16:09
  • Parallel updates are a big red flag! How did you go from updating a table to DDL items with MaxDOP? Commented Aug 26, 2020 at 16:25
  • Why not update the table with a single UPDATE statement? Commented Aug 26, 2020 at 17:53

1 Answer 1

2

Why not update the table with a single UPDATE statement?

If your database is set to READ COMMITTED SNAPSHOT and you can afford to block other sessions from writing to the table during the update, that's the simplest option.

Otherwise update them sequentially in batches (option 2). Running lots of parallel DML statements (Option 1) is too complicated and too prone to blocking and deadlocking issues. IE it's not going to solve all the problems of using a single UPDATE statement, and it introduces new ones.

answered Aug 26, 2020 at 18:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.