From: hubert depesz lubaczewski <depesz@depesz.com>
To: ilies.ovidiu@googlemail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13496: INSERT WHERE NOT EXISTS error
Date: Thu, 9 Jul 2015 18:54:06 +0200
Message-ID: <20150709165406.GA13875@depesz.com> (raw)
In-Reply-To: <20150709155304.15752.16284@wrigleys.postgresql.org>
References: <20150709155304.15752.16284@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Thu, Jul 09, 2015 at 03:53:04PM +0000, ilies.ovidiu@googlemail.com wrote:
> The insert query is like:
> INSERT INTO "website"."search_terms" SELECT 'someID', 'someSearchTerm' WHERE
> NOT EXISTS ( SELECT 1 FROM "website"."search_terms" WHERE (("id" = 'someID')
> OR ("term" = 'someSearchTerm')) LIMIT 1 OFFSET 0 )
> It appears this "upsert" is not safe in high concurency mode ~ 20 users /
> second as I see in Google analytics for that period of time.
Of course it's not safe. Whoever told you it's safe was lying.
There is some time between select check, and the insertion. Hence - race
condition.
More information here:
http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/
depesz
--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: depesz@depesz.com, ilies.ovidiu@googlemail.com
Subject: Re: BUG #13496: INSERT WHERE NOT EXISTS error
In-Reply-To: <20150709165406.GA13875@depesz.com>
References: <20150709155304.15752.16284@wrigleys.postgresql.org> <20150709165406.GA13875@depesz.com>
* 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