Re: Thoughts on how to avoid a massive integer update.

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: "Fehrle, Brian" <bfehrle(at)comscore(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Thoughts on how to avoid a massive integer update.
Date: 2020-05-08 19:49:07
Message-ID: 8FA70C91-57D3-4AD6-9780-48AD0728CF3C@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 = info_table_sid;

update info_table set info_table_sid = 456 where info_table_sid = 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 “orig_id” as just an id and “info_table_sid” 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(at)comscore(dot)com> wrote:
>
>
>
> From: Rob Sargent <robjsargent(at)gmail(dot)com <mailto:robjsargent(at)gmail(dot)com>>
> Date: Friday, May 8, 2020 at 11:05 AM
> To: "Fehrle, Brian" <bfehrle(at)comscore(dot)com <mailto:bfehrle(at)comscore(dot)com>>
> Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>>, "pgsql-general(at)postgresql(dot)org <mailto:pgsql-general(at)postgresql(dot)org>" <pgsql-general(at)postgresql(dot)org <mailto:pgsql-general(at)postgresql(dot)org>>
> Subject: Re: Thoughts on how to avoid a massive integer update.
>
> [External Email]
>
>> Could you show an example table relationship?
>>
>> It’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 = 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tory M Blue 2020-05-08 20:13:27 Re: Memory footprint diff between 9.5 and 12
Previous Message Fehrle, Brian 2020-05-08 19:36:18 Re: Thoughts on how to avoid a massive integer update.