Re: Insert query performance - Mailing list pgsql-general

From David Rowley
Subject Re: Insert query performance
Date
Msg-id CAApHDvq3mwhsiB69eXt6OJJL5=7UnbE74gWvWVJN57yEhrSkkg@mail.gmail.com
Whole thread Raw
In response to Insert query performance  (sud <suds1434@gmail.com>)
Responses Re: Insert query performance
List pgsql-general
On Mon, 19 Aug 2024 at 19:48, sud <suds1434@gmail.com> wrote:
> In a version 15.4 postgres database, Is it possible that , if we have two big range partition tables with foreign key
relationshipsbetween them, insert into the child table can cause slowness if we don't have foreign key index present in
thechild table? Basically it need to make sure the new row already added to parent partition table or not. 

Having an index on the referencing columns is only useful for DELETEs
and UPDATEs affecting the foreign key column(s).  For INSERTs to the
referencing table, technically having indexes there would only slow
down inserts due to the additional overhead of having to maintain the
index, however, the overhead of having the index might be fairly
minuscule when compared to performing a CASCADE UPDATE or DELETE to
the referencing table when the DDL is performed on the referenced
table.

> And if there is any possible way(example query tracing etc) to get the underlying system queries which gets triggered
aspart of the main insert query? For example in above scenario, postgres must be executing some query to check if the
incoming row to the child table already exists in the parent table or not? 

EXPLAIN ANALYZE will list the time it took to execute the foreign key
trigger in the "Trigger for constraint" section.

David



pgsql-general by date:

Previous
From: Muhammad Ikram
Date:
Subject: Re: Insert query performance
Next
From: Tom Lane
Date:
Subject: Re: use of postgres reg* datatypes in user tables?