Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XWWpv-0006ix-9s for pgsql-performance@arkaria.postgresql.org; Tue, 23 Sep 2014 20:37:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XWWpu-0008Mq-LZ for pgsql-performance@arkaria.postgresql.org; Tue, 23 Sep 2014 20:37:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XWWpt-0008Mj-G0 for pgsql-performance@postgresql.org; Tue, 23 Sep 2014 20:37:21 +0000 Received: from oldperseverance.encs.concordia.ca ([132.205.96.92]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XWWpp-0003vH-VU for pgsql-performance@postgresql.org; Tue, 23 Sep 2014 20:37:20 +0000 Received: from cacao.encs.concordia.ca (emilu@cacao.encs.concordia.ca [132.205.47.225]) by oldperseverance.encs.concordia.ca (envelope-from emilu@encs.concordia.ca) (8.13.7/8.13.7) with ESMTP id s8NKbF2c004623 for ; Tue, 23 Sep 2014 16:37:15 -0400 Message-ID: <5421D9FB.2030008@encs.concordia.ca> Date: Tue, 23 Sep 2014 16:37:15 -0400 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.8.0 MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: Which update action quicker? Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on oldperseverance.encs.concordia.ca at 2014/09/23 16:37:15 EDT X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org
Hello list,

For a big table with more than 1,000,000 records, may I know which update is quicker please?

(1) update t1
      set c1 = a.c1
      from a
      where pk and
                 t1.c1       <> a.c1;
 ......
      update t1
      set c_N = a.c_N
      from a
      where pk and
                 t1.c_N       <> a.c_N;


(2)  update t1
      set c1 = a.c1 ,
            c2  = a.c2,
            ...
            c_N = a.c_N
     from a
     where pk AND
               (  t1.c1 <> a.c1 OR t1.c2 <> a.c2..... t1.c_N <> a.c_N)


Or other quicker way for update action?

Thank you
Emi