From: Hilary Forbes <hforbes@dmr.co.uk>
To: pgsql-performance@postgresql.org
Subject: Slow update
Date: Mon, 12 Sep 2005 10:14:25 +0100
Message-ID: <5.1.0.14.0.20050912100150.01f47f18@mailserver.dmr.co.uk> (raw)
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?
(Please don't ask why tableA and tableB are not amalgamated - that's another story altogether!!!)
Many thanks in advance
Hilary
Hilary Forbes
The DMR Information and Technology Group (www.dmr.co.uk)
Direct tel 01689 889950 Fax 01689 860330
DMR is a UK registered trade mark of DMR Limited
**********************************************************
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: hforbes@dmr.co.uk
Subject: Re: Slow update
In-Reply-To: <5.1.0.14.0.20050912100150.01f47f18@mailserver.dmr.co.uk>
References: <5.1.0.14.0.20050912100150.01f47f18@mailserver.dmr.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox