Re: Degraded performance during table rewrite - Mailing list pgsql-general

From Tom Lane
Subject Re: Degraded performance during table rewrite
Date
Msg-id 1206017.1593892736@sss.pgh.pa.us
Whole thread Raw
In response to Re: Degraded performance during table rewrite  (Mohamed Wael Khobalatte <mkhobalatte@grubhub.com>)
Responses Re: Degraded performance during table rewrite
List pgsql-general
Mohamed Wael Khobalatte <mkhobalatte@grubhub.com> writes:
> Tom, I think I understood what you meant after getting some sleep. What I
> do now is:

> - Initially load a lot of ids, say a million.
> - Then I slice that array by my preferred batch, say a 10000.
> -  Loop through these slices and run an improved query, which looks like
> this:

>         WITH del AS (
>           DELETE FROM #{old_table}
>           WHERE id >= #{first_id_in_slice} AND id <= #{last_id_in_slice}
>           RETURNING *
>         )
>         INSERT INTO #{table}
>         SELECT * FROM del
>         RETURNING id

Right, the problem occurs when you're deleting stuff that's at the end
of the id range, and have already deleted stuff that was previously the
end of the range.  If you start somewhere in the middle and work towards
the end, you dodge that problem, even for the very last delete that
*is* handling the endmost ids.

            regards, tom lane



pgsql-general by date:

Previous
From: Mohamed Wael Khobalatte
Date:
Subject: Re: Degraded performance during table rewrite
Next
From: Mohamed Wael Khobalatte
Date:
Subject: Re: Degraded performance during table rewrite