Weird slow update case on 0 record

  • I have this statement, taking 0 sec and returning 0 rows

    Select * from A join B on (a.Company = b.company AND a.id= b.id)

    If i try to update B

    Update B set Company = b.company from A join B on (a.Company = b.company AND a.id= b.id)

    this take 8 sec or more for 0 records

    If the Update found a row or more, everything runs smootly (within 1 second).

    Any hints?

  • I'm a little confused. You don't have any kind of WHERE clause on your queries.

    This will be updating all records in the table where the join criteria is true, if any matched. Since nothing matches, it's probably just scanning both tables. Do your tables have indexes? Have you looked at an execution plan?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Hi,

    yes i had look at the exec plan, nothing seems wrong using Clustered index Update (92%) -> Merge join (1%) -> Index Seek on both table accounting for 7%.

    Exacte same plan for 0 records or more. 0 still take 8sec and more less than 1sec.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply