Re: update - which way quicker?

From: paul socha <pawel(dot)socha(at)gmail(dot)com>
To: emilu(at)encs(dot)concordia(dot)ca
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: update - which way quicker?
Date: 2008-08-28 21:13:55
Message-ID: A826B099-A9BA-4CDF-A7BA-AAB0BC739E67@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On 2008-08-28, at 21:31, Emi Lu wrote:

> Good morning,
>
> Tried to compare Table1 based on Table2
>
> . update table1.col = false
> if table1.pk_cols not in table2.pk_cols
>
>
>
> For the following two ways, (2) always performs better than (1) right,
> and I need your inputs.
> ======================================================================
> ==
> (1) update table1
> set col = false
> where table1.pk_co1 || table1.pk_col2.... || table1.pk_colN
>
> NOT IN
>
> (select pk_co1 || pk_col2.... || pk_colN
> from table2
> )
>
> (2) ResultSet(rs) =
> select pk_col1||pk_col2... || pk_colN
> from table1
> left join table2 using (pk_col1..., pk_colN)
> where table2.pk_col1 is null
>
> Then for each rs record, do:
> update table1
> set col = false
> where col1||... colN in rs.value
>
> Thanks a lot!
>
> --
> Sent via pgsql-performance mailing list (pgsql-
> performance(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance

Check EXISTS

http://www.postgresql.org/docs/8.3/interactive/functions-subquery.html

Serdecznie pozdrawiam

Pawel Socha
pawel(dot)socha(at)gmail(dot)com

programista/administrator

perl -le 's**02).4^&-%2,).^9%4^!./4(%2^3,!#+7!2%^53%2&**y%& -;^[%"`-
{ a%%s%%$_%ee'

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message cluster 2008-08-28 21:29:09 Re: Best hardware/cost tradoff?
Previous Message Matthew Wakeling 2008-08-28 20:29:08 Re: select on 22 GB table causes "An I/O error occured while sending to the backend." exception