Re: Slow update with simple query - Mailing list pgsql-performance

From Ragnar
Subject Re: Slow update with simple query
Date
Msg-id 1166008803.6369.94.camel@localhost.localdomain
Whole thread Raw
In response to Slow update with simple query  (Arnaud Lesauvage <thewild@freesurf.fr>)
Responses Re: Slow update with simple query
List pgsql-performance
On mið, 2006-12-13 at 11:51 +0100, Arnaud Lesauvage wrote:
> Hi list !
>
> I am running a query to update the boolean field of a table based on
> another table's fields.
>
> The query is (changed names for readability):
> UPDATE t1
> SET booleanfield = (t2.field1 IN ('some', 'other') AND t2.field2 = 'Y')
> FROM t2
> WHERE t1.uid = t2.uid
>
> t2.uid is the PRIMARY KEY.
> t2 only has ~1000 rows, so I think it fits fully in memory.
> t1 as ~2.000.000 rows.
> There is an index on t1.uid also.
>
> The explain (sorry, not explain analyze available yet) is :
>
> Hash Join  (cost=112.75..307410.10 rows=2019448 width=357)
>    Hash Cond: ("outer".uid= "inner".uid)
>    ->  Seq Scan on t1 (cost=0.00..261792.01 rows=2033001 width=340)
>    ->  Hash  (cost=110.20..110.20 rows=1020 width=53)
>          ->  Seq Scan on t2  (cost=0.00..110.20 rows=1020 width=53)
>
> My query has been running for more than 1.5 hour now, and it is still running.
> Nothing else is running on the server.
> There are two multicolumn-indexes on this column (both are 3-columns indexes). One of them has a
> functional column (date_trunc('month', datefield)).
>
> Do you think the problem is with the indexes ?

I guess so. are you sure about the index on t1.uid?
what are the column definitions for t1.uid and t2.uid ?
are they the same ?
you should ba able to get a plan similar to:
Merge Join  (cost=0.00..43.56 rows=1000 width=11)
   Merge Cond: ("outer".uid = "inner".uid)
   ->  Index Scan using t1i on t1  (cost=0.00..38298.39 rows=2000035
width=10)
   ->  Index Scan using t2i on t2  (cost=0.00..26.73 rows=1000 width=5)

what postgres version are you using ?

gnari




>
> The hardware is not great, but the database is on a RAID1 array, so its not bad either.
> I am surprised that it takes more than 3 seconds per row to be updated.
>
> Thanks for your opinion on this !
>
> --
> Arnaud
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>


pgsql-performance by date:

Previous
From: Arnaud Lesauvage
Date:
Subject: Slow update with simple query
Next
From: Arnaud Lesauvage
Date:
Subject: Re: Slow update with simple query