Re: Slow update with simple query

From: Arnaud Lesauvage <thewild(at)freesurf(dot)fr>
To: Ragnar <gnari(at)hive(dot)is>
Cc: Jens Schipkowski <jens(dot)schipkowski(at)apus(dot)co(dot)at>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow update with simple query
Date: 2006-12-13 15:19:55
Message-ID: 45801A1B.6070200@freesurf.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Ragnar a écrit :
> On mið, 2006-12-13 at 14:38 +0100, Arnaud Lesauvage wrote:
>> Jens Schipkowski a écrit :
>> > On Wed, 13 Dec 2006 13:23:41 +0100, Arnaud Lesauvage <thewild(at)freesurf(dot)fr>
>> >> Why is this query better than the other one ? Because it runs the
>> >> "(field IN ('some','other') AND field2 = 'Y')" once and then executes
>> >> the join with the resulting set ?
>> > True. The Subselect in FROM clause will be executed once and will be
>> > joined using the condition at where clause. So your condition at t2 is not
>> > executed for each row in t1(2mio records) but for each row in t2(1k
>> > records). And the boolean value is already set during update.
>>
>> OK Jens, thanks for clarifying this.
>> I thought the planner could guess what to do in such cases.
>
> don't worry, it will.
> this is not your problem

Indeed, the new query does not perform that well :

"Hash Join (cost=112.75..307504.97 rows=2024869 width=355) (actual time=53.995..246443.811 rows=2020061 loops=1)"
" Hash Cond: ("outer".uid = "inner".uid)"
" -> Seq Scan on t1 (cost=0.00..261792.01 rows=2033001 width=338) (actual time=19.342..234304.499 rows=2033001 loops=1)"
" -> Hash (cost=110.20..110.20 rows=1020 width=53) (actual time=4.853..4.853 rows=1020 loops=1)"
" -> Seq Scan on t2 (cost=0.00..110.20 rows=1020 width=53) (actual time=0.017..2.586 rows=1020 loops=1)"
"Total runtime: 2777844.892 ms"

I removed all unnecessary indexes on t1 before running the query (I left the index on uid and the multicolumn index containind the updated field).
I believe the multicolumn-functional-index computation is taking some time here, isn't it ?

Regards
--
Arnaud

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Cosimo Streppone 2006-12-13 16:11:59 Re: New to PostgreSQL, performance considerations
Previous Message Ragnar 2006-12-13 14:49:00 Re: Slow update with simple query