Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX8zm-00019a-Ep for pgsql-general@arkaria.postgresql.org; Fri, 08 May 2020 19:49:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jX8zl-0004DY-Bj for pgsql-general@arkaria.postgresql.org; Fri, 08 May 2020 19:49:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX8zk-0004DF-Tf for pgsql-general@lists.postgresql.org; Fri, 08 May 2020 19:49:17 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jX8ze-0003HO-GA for pgsql-general@postgresql.org; Fri, 08 May 2020 19:49:15 +0000 Received: by mail-io1-xd32.google.com with SMTP id u11so3008956iow.4 for ; Fri, 08 May 2020 12:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=sl14wHQWzw/y8nk30Pi2xOd0AIIqroq/7568kT0oKj8=; b=YhC/9khULQJ6Nq/boLmdnifrACwv0rsMzS7PPZ2Ig3rWWooP8BN3bUAul0x3Y+nmHb FhHxuNosmydi4ur0Av/jPfvR5kreaiguL5DSz2qNS25WgqRKZvQzmrAFIL91iQBK3uWQ tK8AhC5NzH5/CaEmLXHzwyFI7Vunl2PnjH/BDIsguC8GmfAihfYwUQytQFtaRGFlCB0l TFHX2TejQLJ0wB3csbdAIw7xqh7nMlSzgglgbq7jCQR2ir2babJmEGTD+YzjYxx40FpF 0TmExh4T7D/qmD1x5lxZLDvLW/1beFNOwMgiJRTaW2Bhs8/yLzLc+OGovlEwnrQQlcJJ dWyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=sl14wHQWzw/y8nk30Pi2xOd0AIIqroq/7568kT0oKj8=; b=qCFx9ApXDjAJAbOiRIeJqKlWlpPaUGieYU75/3iVQHcwNR7V4S2sHhpVJhuD+W/Peb GwwJP3aiCt0lWz2tVYumKzGA71CID7NVdXoeVijW5rJDSM0IfR1cv/PS22sU2BCC5DMa RidkKXpD2dYaY+7yxPU8MYnESFA9CDjMQyUKuBrobZr375YOGUeR4dQnh6AWZrsAm84n mfvNsGu42WPX28Rj+mi+BN/KJDNP++NYmXTyBXT8yLxPsFSSWJ/wl/Ij5QB9u9eYG4Gd +9s7yOi0eAG59KbcIbmohI0mUayC93QHkoQZm06lSloDqjE/04k7a8bkqzwvKgL8LWt4 +iTg== X-Gm-Message-State: AGi0PuZGzNlH4rdL7QQ4lrcKbAMvtwHe+uNf9WRHQ/4k59+pGiwPnrk5 7jaWlRLFJTV2hf6jz7u/WDA= X-Google-Smtp-Source: APiQypI8ZGPFEjIQolhatD5fOMrbf2RhqBAAQOU3xNflr4mB/HD4t7Xca8TcH87Zq2NRcxBVvbn9iA== X-Received: by 2002:a5d:8417:: with SMTP id i23mr4369387ion.186.1588967349389; Fri, 08 May 2020 12:49:09 -0700 (PDT) Received: from ?IPv6:2601:681:5500:dde0:13f:ef9:c6d0:c102? ([2601:681:5500:dde0:13f:ef9:c6d0:c102]) by smtp.gmail.com with ESMTPSA id u4sm1063647iop.1.2020.05.08.12.49.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2020 12:49:08 -0700 (PDT) From: Rob Sargent Message-Id: <8FA70C91-57D3-4AD6-9780-48AD0728CF3C@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_93582E05-DE12-46EC-8EB2-AB473B787D83" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: Thoughts on how to avoid a massive integer update. Date: Fri, 8 May 2020 13:49:07 -0600 In-Reply-To: <8491BCF6-2163-4765-BCCF-E96B845D7427@comscore.com> Cc: "pgsql-general@postgresql.org" To: "Fehrle, Brian" References: <129e882d-fe4c-0ce9-1966-acbcbf94c309@aklaver.com> <0F5992D4-9317-4007-9036-202DC89BA0D8@comscore.com> <8491BCF6-2163-4765-BCCF-E96B845D7427@comscore.com> X-Mailer: Apple Mail (2.3608.80.23.2.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_93582E05-DE12-46EC-8EB2-AB473B787D83 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Well as I said, I think you could add a column to info_table alter table info_table add orig_id int; update info_table set orig_id =3D info_table_sid; update info_table set info_table_sid =3D 456 where info_table_sid =3D = 456;=20 alter table data_table drop reference NOT SQL alter table data_table make reference to info_table.orig_id NOT SQL you have to do the second block per orig_id and the third block per table at your reports needing the new value will of course need to do the join = and get the updated value which now resides in the ill-name = info_table_sid. =20 This leaves =E2=80=9Corig_id=E2=80=9D as just an id and = =E2=80=9Cinfo_table_sid=E2=80=9D as an editable attribute Nothing is broken other than the per-table lock while you switch the = foreign key > On May 8, 2020, at 1:36 PM, Fehrle, Brian = wrote: >=20 > =20 > =20 > From: Rob Sargent > > Date: Friday, May 8, 2020 at 11:05 AM > To: "Fehrle, Brian" > > Cc: Adrian Klaver >, "pgsql-general@postgresql.org = " > > Subject: Re: Thoughts on how to avoid a massive integer update. > =20 > [External Email] >=20 >> Could you show an example table relationship? >>=20 >> It=E2=80=99s a simple one-to-many relationship: >> *Info_table* >> info_table_sid integer >>=20 >>=20 >> *data_table* >> data_table_sid integer, >> info_table_id integer references info_table(info_table_sid), >>=20 >>=20 >>=20 >=20 > =20 > Right, and now you wish to change the values in the referenced table = (info_table.info_table_sid) correct? =20 > =20 > =20 > Correct. If info_table.info_table_sid =3D 123 and many rows in = data_table point to it, the ID needs to be changed to 456 in the = info_table, as well as all the columns in the data_table. --Apple-Mail=_93582E05-DE12-46EC-8EB2-AB473B787D83 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Well = as I said, I think you could add a column to info_table
alter table info_table add orig_id int;
update info_table set orig_id =3D info_table_sid;

update info_table set = info_table_sid =3D 456 where info_table_sid =3D 456; 

alter table data_table = drop reference NOT SQL
alter = table data_table make reference to info_table.orig_id NOT = SQL

you have to do the second block per = orig_id
and the third block per table

at your reports needing = the new value will of course need to do the join and get the updated = value which now resides in the ill-name info_table_sid.  

This leaves = =E2=80=9Corig_id=E2=80=9D as just an id and =E2=80=9Cinfo_table_sid=E2=80=9D= as an editable attribute

Nothing is broken other than the per-table lock while you = switch the foreign key



On May = 8, 2020, at 1:36 PM, Fehrle, Brian <bfehrle@comscore.com> wrote:

 
 
From: Rob Sargent <robjsargent@gmail.com>
Date: Friday, May 8, 2020 at = 11:05 AM
To: "Fehrle, Brian" <bfehrle@comscore.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>, "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Subject: Re: Thoughts on how to = avoid a massive integer update.
 

[External Email]

   Could you = show an example table relationship?

It=E2=80=99= s a simple one-to-many relationship:
*Info_table*
info_table_sid integer


*data_table*
data_table_sid integer,
info_table_id integer references = info_table(info_table_sid),



 
Right, and now you wish to change = the values in the referenced table = (info_table.info_table_sid) correct?  
 
 
Correct. If info_table.info_table_sid =3D 123 and many rows = in data_table point to it, the ID needs to be changed to 456 in the = info_table, as well as all the columns in the data_table.

= --Apple-Mail=_93582E05-DE12-46EC-8EB2-AB473B787D83--