From: rihad <rihad@mail.ru>
To: pgsql-general General <pgsql-general@postgresql.org>
Subject: Does "ON UPDATE" for foreign keys require index?
Date: Thu, 25 Apr 2019 13:29:31 +0400
Message-ID: <6cb9e903-b7c7-23c1-65b4-5df8dbdfc1db@mail.ru> (raw)
Hi. Say I have column A.b_id which references B.id (which is a primary
key) and as such it is declared as a foreign key constraint. A.b_id has
no index because it doesn't need one. What happens when table B's rows
are modified (but never deleted)? Will PG still have have to scan A fo
find A.b_id to do nothing with it? )) B.id itself is never modified,
it's just a normal serial value typically used for id's.
The docs are a bit ambiguous:
> Since a DELETE of a row from the referenced table *or an **UPDATE**of
> a referenced column* will require a scan of the referencing table for
> rows matching the old value, it is often a good idea to index the
> referencing columns too. Because this is not always needed, and there
> are many choices available on how to index, declaration of a foreign
> key constraint does not automatically create an index on the
> referencing columns.
>
>
https://www.postgresql.org/docs/9.6/ddl-constraints.html
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: rihad@mail.ru
Subject: Re: Does "ON UPDATE" for foreign keys require index?
In-Reply-To: <6cb9e903-b7c7-23c1-65b4-5df8dbdfc1db@mail.ru>
References: <6cb9e903-b7c7-23c1-65b4-5df8dbdfc1db@mail.ru>
* 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