postgresql 12 runs out of memory when updating a partitioned table with subquery

From: Max Vikharev <bm(dot)kinder(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: postgresql 12 runs out of memory when updating a partitioned table with subquery
Date: 2020-07-11 20:32:03
Message-ID: CACRpr1NaU8x_+y63RfBf2QzZJVPPqR-xWcV9WjAgPzDOe6rkUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

I have 'out of mem' on postgresql 12 when updating a partitioned table with
subquery.
I have Project and Content relations. Content is partitioned by type and
subpartitioned by project.
Schema
https://gist.github.com/mvikharev/f770914a8bb7f814c5aab4fd1da109f7#file-schema-sh

When I update content of some type of a single project with subquery -
postgresql query hangs and runs out of mem.

Test env has the following settings:
1. 4G RAM, 2 CPU.
2. Ubuntu 16.04
3. Default postgresql settings (details in link
https://gist.github.com/mvikharev/f770914a8bb7f814c5aab4fd1da109f7#file-configuration
)
4. 100 rows in 100 subpartitions for 2 partitions.

Scripts to reproduce the problem
https://gist.github.com/mvikharev/f770914a8bb7f814c5aab4fd1da109f7

Reproduce
1. Create schema
createdb test
./schema.sh > schema.sql
./data.sh > data.sql
psql test < schema.sql
psql test < data.sql

2. Update with prepared ids - no problem
SELECT id into agg
FROM "content"
WHERE "content"."id" IN
(SELECT U0."id" AS Col1
FROM "content" U0
INNER JOIN "project" U2 ON (U0."project_id" = U2."id")
WHERE (U0."service_id" = 2
AND U0."type_id" = 0
AND U2."user_id" = 1));
SELECT 1000

UPDATE "content"
SET "value" = '1'
WHERE "content"."id" IN (select id from agg);
UPDATE 1000

3. Update with subquery - out of mem
UPDATE "content"
SET "value" = '1'
WHERE "content"."id" IN
(SELECT U0."id" AS Col1
FROM "content" U0
INNER JOIN "project" U2 ON (U0."project_id" = U2."id")
WHERE (U0."service_id" = 2
AND U0."type_id" = 0
AND U2."user_id" = 1));

^CCancel request sent
^CCancel request sent
^CCancel request sent
^CCancel request sent
^CCancel request sent
server closed the connection unexpectedly

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2020-07-12 05:50:29 Re: postgresql 12 runs out of memory when updating a partitioned table with subquery
Previous Message legrand legrand 2020-07-11 08:01:49 Re: BUG #16535: Implementing Autonomous Transactions in Postgresql