From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matthew Woodcraft <matthew@woodcraft.me.uk>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: INSERT locking order
Date: Thu, 09 Jan 2020 16:27:06 -0500
Message-ID: <14928.1578605226@sss.pgh.pa.us> (raw)
In-Reply-To: <1578602959.23rey5xcjc.astroid@golux.woodcraft.me.uk>
References: <1578602959.23rey5xcjc.astroid@golux.woodcraft.me.uk>
Matthew Woodcraft <matthew@woodcraft.me.uk> writes:
> In an INSERT, are the rows guaranteed to be inserted in the order that
> the source query returns its rows, for locking purposes?
I dunno that we "guarantee" that, but it's hard to see why the
code would behave any differently, at present.
> and I run two concurrent copies of
> INSERT INTO foo (SELECT n FROM ... ORDER BY n);
> is there any guarantee that I'll get a unique constraint violation
> rather than a deadlock?
Well, the issue there is not about the physical insertion order
but the order in which the uniqueness checks happen. I think
you'd be all right with a traditional-style PG index, but maybe
not with a deferrable unique constraint.
regards, tom lane
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: tgl@sss.pgh.pa.us, matthew@woodcraft.me.uk
Subject: Re: INSERT locking order
In-Reply-To: <14928.1578605226@sss.pgh.pa.us>
References: <1578602959.23rey5xcjc.astroid@golux.woodcraft.me.uk> <14928.1578605226@sss.pgh.pa.us>
* 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