Re: [PERFORMANCE] slow small delete on large table

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [PERFORMANCE] slow small delete on large table
Дата
Msg-id 18315.1077600238@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [PERFORMANCE] slow small delete on large table  ("Ed L." <pgsql@bluepolka.net>)
Ответы Re: [PERFORMANCE] slow small delete on large table  ("Ed L." <pgsql@bluepolka.net>)
Список pgsql-performance
"Ed L." <pgsql@bluepolka.net> writes:
> If I could say it the way I think for a simple example, it'd be
> like this:

>     delete from mytable
>     where posteddatetime < now() - '90 days'
>     limit 100;

> Of course, that's not legal 7.3.4 syntax.

Assuming you have a primary key on the table, consider this:

CREATE TEMP TABLE doomed AS
  SELECT key FROM mytable WHERE posteddatetime < now() - '90 days'
  LIMIT 100;

DELETE FROM mytable WHERE key = doomed.key;

DROP TABLE doomed;

Depending on the size of mytable, you might need an "ANALYZE doomed"
in there, but I'm suspecting not.  A quick experiment suggests that
you'll get a plan with an inner indexscan on mytable.key, which is
exactly what you need.

See also Chris Browne's excellent suggestions nearby, if you are willing
to make larger readjustments in your thinking...

            regards, tom lane

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

Предыдущее
От: Christopher Browne
Дата:
Сообщение: Re: [PERFORMANCE] slow small delete on large table
Следующее
От: "Eric Jain"
Дата:
Сообщение: Re: Slow join using network address function