From: Haug Bürger <haug.buerger@zalando.de>
To: pgsql-general@postgresql.org
Subject: Bad performance with cascaded deletes
Date: Tue, 12 Jun 2018 09:26:43 +0200
Message-ID: <5a4cfb77-6095-5230-8019-49f99c9ecefa@zalando.de> (raw)
I have an issue with delete performance I can't explain.
Delete on zpg_data.session (cost=190.51..4491.20 rows=500 width=46)
...
Planning time: 0.222 ms
Trigger RI_ConstraintTrigger_a_16481 for constraint
availability_cache_ac_session_id_fkey: time=350.116 calls=500
For me this reads like the delete takes 0.2ms and the cascaded delete
takes 350ms. There is a primary key (index) on the availability_cache
table and if I delete it manually deleting with an id is pretty fast.
For me it looks like the trigger doesn't use the primary key/index.
Any ideas why the trigger is slow or how to get a plan for the trigger?
Thanks for help
Haug
Table "zpg_data.session"
Column | Type | Nullable
| Default | Storage |
-----------------------------------+--------------------------+----------+--------------+----------+
id | uuid | not null
| | plain |
... rows deleted ...
Indexes:
"pk_session" PRIMARY KEY, btree (id)
Referenced by:
TABLE "zpg_data.availability_cache" CONSTRAINT
"availability_cache_ac_session_id_fkey" FOREIGN KEY (ac_session_id)
REFERENCES zpg_data.session(id) ON DELETE CASCADE
Table "zpg_data.availability_cache"
Column | Type | Nullable | Default |
Storage |
---------------+--------------------------+----------+-------------+----------+
ac_session_id | uuid | not null | |
plain |
ac_created | timestamp with time zone | not null | |
plain |
ac_content | jsonb | not null | '{}'::jsonb |
extended |
Indexes:
"pk_availability_cache" PRIMARY KEY, btree (ac_session_id)
Foreign-key constraints:
"availability_cache_ac_session_id_fkey" FOREIGN KEY (ac_session_id)
REFERENCES zpg_data.session(id) ON DELETE CASCADE
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: haug.buerger@zalando.de
Subject: Re: Bad performance with cascaded deletes
In-Reply-To: <5a4cfb77-6095-5230-8019-49f99c9ecefa@zalando.de>
References: <5a4cfb77-6095-5230-8019-49f99c9ecefa@zalando.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox