Re: Long running INSERT+SELECT query - Mailing list pgsql-general

From David G. Johnston
Subject Re: Long running INSERT+SELECT query
Date
Msg-id CAKFQuwYwAmy_12Pa95GLW+0n_dDVzuvL2K4y8egegGXiAj=wNA@mail.gmail.com
Whole thread Raw
In response to Re: Long running INSERT+SELECT query  (Vitaliy Garnashevich <vgarnashevich@gmail.com>)
List pgsql-general
On Thu, Apr 26, 2018 at 1:32 PM, Vitaliy Garnashevich <vgarnashevich@gmail.com> wrote:
The aggregated table has hundreds of millions of rows, and the query runs for many hours (which is one of the reasons why it's better not to fail)
​[...]​
 
Maybe this could be solved by calculating results into a temporary table, which would not check foreign key constraints, and then copy the data into the actual results table, while checking each row for FK consistency and skipping if necessary.

Me, I'd try very hard to design things so the final calculation goes into an actual results table that omits FK constraints​ and wouldn't try to "skip if necessary".  You are already running an hours-long query - the users of said information needs to understand that what they are seeing does not reflect changes in the subsequent hour(s) since it started and that certain related records being no longer present doesn't detract from the fact that they were present "back then" and thus represent valid data at that point in time.

David J.

pgsql-general by date:

Previous
From: Vitaliy Garnashevich
Date:
Subject: Re: Long running INSERT+SELECT query
Next
From: Alvaro Herrera
Date:
Subject: Re: Long running INSERT+SELECT query