update small data is slow performance ?

ahmed salah 3,216 Reputation points
2022-02-24T07:56:45.633+00:00

i work on sql server 2019 i face issue
when make update it take 20 second for 162 rows only
so how to enhance that please

Update FT SET
 ft.ValueName=avo.name
FROM #package FT 
inner join  parts.Nop_PackageAttribute PA   with(nolock)on PA.PackageID=ft.PackageID and PA.[Key]=FT.ZfeatureId 
inner join  Nop_AcceptedValuesOption AVO with(nolock) ON convert(varchar(20),AVO.AcceptedValuesOptionID)=PA.Value 
where FT.AcceptedValueID is not null

execution plan as below

https://www.brentozar.com/pastetheplan/?id=H1jdK3Veq

table

create table #package
(
id int PRIMARY KEY IDENTITY(1,1),
ZfeatureId INT NULL,
AcceptedValueID INT NULL,
PackageID INT NULL,
ValueName NVARCHAR(2000) default ''
)
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,818 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,639 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 44,656 Reputation points
    2022-02-24T12:52:39.96+00:00

    Review the execution plan, there are at least 2 scans and an expensive hash match; and this because of missing suitable indexes.


  2. Erland Sommarskog 111.4K Reputation points MVP
    2022-02-24T23:03:07.35+00:00

    You could try changing:

    ``
    convert(varchar(20),AVO.AcceptedValuesOptionID)=PA.Value

    to
    

    AVO.AcceptedValuesOptionID = try_convert(int, PA.Value)

    But even better you may want to review the overall table design. This kind of type conversions are a very good recipe for bad performance.
    
    0 comments No comments

  3. Seeya Xi-MSFT 16,471 Reputation points
    2022-02-25T10:09:07.78+00:00

    Hi @ahmed salah ,

    Please read this article about many common sign meanings in execution plan:
    https://www.red-gate.com/simple-talk/databases/sql-server/performance-sql-server/graphical-execution-plans-for-simple-sql-queries/
    In your execution plan, the number of hash match is high, which sometimes indicates:
    a missing or incorrect index
    a missing WHERE clause

    In addition, you should pay attention to update warning in your execution plan and Erland give his suggestion.
    Then you can check the new execution plan.

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    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.