Update from other tables slow - Mailing list pgsql-novice

From Carlo Stonebanks
Subject Update from other tables slow
Date
Msg-id BAYC1-PASMTP10E75613B2D319AEBA902196350@CEZ.ICE
Whole thread Raw
Responses Re: Update from other tables slow  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
This question is so silly, that I must hang my head in shame and admit it's
a novice question.

Frequently on our DB we need to run large updates on a table, typically
involving over 100K rows. These nearly ALWAYS involve values from other
tables. But the updates take so long that we think the process has stalled
on some sort of deadly-embrace locking scenario and we cancel it.

Is there anything wrong with this UPDATE statement?

update mdx_core.provider
set
   middle_name = fix.middle_name,
   display_name = fix.display_name
from mdx_import._fix_mnames as fix
where provider.provider_id = fix.provider_id;

Even though _fix_mnames has an index on provider_id, it took so long that I
cancelled it and rewrote it, replacing it with this absolutely silly-looking
statement:

update mdx_core.provider
set
   middle_name = (
      select middle_name
      from mdx_import._fix_mnames as fix
      where fix.provider_id = provider.provider_id),
   display_name = (
      select display_name
      from mdx_import._fix_mnames as fix
      where fix.provider_id = provider.provider_id)
where provider.provider_id in (
   select provider_id from mdx_import._fix_mnames)

This worked, after running for 25 minutes on 276K rows. TWENTY FIVE MINUTES?

The performance of our server on other operations are great, but this can't
be normal for an enterprise-scale SQL server, can it? What am I doing wrong?

TIA

Carlo


pgsql-novice by date:

Previous
From: e-letter
Date:
Subject: maths functions and spreadsheet
Next
From: Richard Broersma Jr
Date:
Subject: Re: maths functions and spreadsheet