pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <ringerc@ringerc.id.au>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: McKinzie, Alan (Alan) <alanmck@avaya.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Are there known performance issues with defining all Foreign Keys as deferrable initially immediate
Date: Mon, 17 Sep 2012 10:59:20 +0800
Message-ID: <50569208.8050408@ringerc.id.au> (raw)
In-Reply-To: <11998.1347809835@sss.pgh.pa.us>
References: <E151F470685C15418AEA609E825A171022EC8EA823@DC-US1MBEX4.global.avaya.com>
	<5055D7FF.2070908@ringerc.id.au>
	<5055DE3D.4040603@ringerc.id.au>
	<11998.1347809835@sss.pgh.pa.us>

On 09/16/2012 11:37 PM, Tom Lane wrote:
> Craig Ringer <ringerc@ringerc.id.au> writes:
>> Found it, it's in the NOTES for CREATE TABLE.
>> http://www.postgresql.org/docs/current/static/sql-createtable.html:
>
>> When a UNIQUE or PRIMARY KEY constraint is not deferrable, PostgreSQL
>> checks for uniqueness immediately whenever a row is inserted or
>> modified. The SQL standard says that uniqueness should be enforced only
>> at the end of the statement; this makes a difference when, for example,
>> a single command updates multiple key values. To obtain
>> standard-compliant behavior, declare the constraint as DEFERRABLE but
>> not deferred (i.e., INITIALLY IMMEDIATE). Be aware that this can be
>> significantly slower than immediate uniqueness checking.
>
> Note that that is addressing uniqueness constraints, and *only*
> uniqueness constraints.  Foreign key constraints are implemented
> differently.  There is no equivalent to an immediate check of a foreign
> key constraint --- it's checked either at end of statement or end of
> transaction, depending on the DEFERRED property.  So there's really no
> performance difference for FKs, unless you let a large number of pending
> checks accumulate over multiple commands within a transaction.

Ah, thanks. I missed that detail.

--
Craig Ringer





view thread (6+ messages)  latest in thread

Message-ID: <50569208.8050408@ringerc.id.au>
Permalink:  ../50569208.8050408@ringerc.id.au/
Also on:    postgresql.org/message-id/50569208.8050408@ringerc.id.au

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: ringerc@ringerc.id.au, tgl@sss.pgh.pa.us, alanmck@avaya.com
  Subject: Re: Are there known performance issues with defining all Foreign Keys as deferrable initially immediate
  In-Reply-To: <50569208.8050408@ringerc.id.au>

* 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