Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT

Поиск
Список
Период
Сортировка
От Gunnlaugur Thor Briem
Тема Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT
Дата
Msg-id CAPs+M8JaFmns1me5PB5TE9jsTscM0yW9ONL4JwzFHmcbQ-9p-g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
Ответы Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Список pgsql-performance
On Sat, Mar 7, 2015 at 3:44 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote:
Another possibility is that this is part
of some large batch, and autovacuum simply did not have change to do the
work.

Yes, I think that's it: I've just realized that immediately prior to the INSERT, in the same transaction, an unfiltered DELETE has been issued; i.e. the whole table is being rewritten. Then the INSERT is issued ... with a WHERE clause on non-existence in the (now empty) table.

In that case of course the WHERE clause is unnecessary, as it will always evaluate as true (and we've locked the whole table for writes). Looks like it is a lot worse than unnecessary, though, if it triggers this performance snafu in EXPLAIN INSERT.

This seems very likely to be the explanation here. So our workaround will be to simply omit the WHERE clause in those cases where the full DELETE has been issued. (And then vacuum afterwards.)

(Even better, just make the new table not temporary, and have it replace the former table altogether. But that's for later; requires some broader changes in our application.)

I'll report back if I *do* see the problem come up again despite this change.

Thanks all for your help figuring this out!

Best regards,

Gulli

В списке pgsql-performance по дате отправления:

Предыдущее
От: Nicolas Paris
Дата:
Сообщение: Re: PG 9.3 materialized view VS Views, indexes, shared memory
Следующее
От: Tom Lane
Дата:
Сообщение: Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT