Skip site navigation (1) Skip section navigation (2)

Re: Slow update

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Hilary Forbes <hforbes(at)dmr(dot)co(dot)uk>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow update
Date: 2005-09-12 13:34:11
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
On Mon, Sep 12, 2005 at 10:14:25 +0100,
  Hilary Forbes <hforbes(at)dmr(dot)co(dot)uk> wrote:
> Hello everyone
> I must be doing something very wrong here so help please!  I have two tables
> tableA has 300,000 recs
> tableB has 20,000 recs
> I need to set the value of a field in table A to a value in table B depending on the existence of the record in table B.  So what I have done is
> UPDATE tableA set a.val1=b.somefield FROM tableA a, tableB b WHERE a.key1=b.key1;
> The primary key of tableA is key1 and that of tableB is key1 ie the join is on primary keys.
> The "optimizer" has elected to d a sequential scan on tableA to determine which fields to update rather than the query being driveb by tableB and it is taking forever.  Surely I must be able to force the system to read down tableB in preference to reading down tableA?

It would help to see the exact query and the explain analyze output. Hopefully
you didn't really write the query similar to above, since it is using illegal
syntax and the if it was changed slightly to become legal than it would do a
cross join of table A with the inner join of tableA and tableB, which isn't
what you want.

In response to

  • Slow update at 2005-09-12 09:14:25 from Hilary Forbes

pgsql-performance by date

Next:From: Tom LaneDate: 2005-09-12 14:07:26
Subject: Re: Slow update
Previous:From: Greg Sabino MullaneDate: 2005-09-12 13:26:44
Subject: Re: Prepared statement not using index

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group