pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13496: INSERT WHERE NOT EXISTS error
3+ messages / 3 participants
[nested] [flat]

* BUG #13496: INSERT WHERE NOT EXISTS error
@ 2015-07-09 15:53 ilies.ovidiu@googlemail.com
  2015-07-09 16:53 ` Re: BUG #13496: INSERT WHERE NOT EXISTS error David G. Johnston <david.g.johnston@gmail.com>
  2015-07-09 16:54 ` Re: BUG #13496: INSERT WHERE NOT EXISTS error hubert depesz lubaczewski <depesz@depesz.com>
  0 siblings, 2 replies; 3+ messages in thread

From: ilies.ovidiu@googlemail.com @ 2015-07-09 15:53 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13496
Logged by:          Radu Ovidiu
Email address:      ilies.ovidiu@googlemail.com
PostgreSQL version: 9.4.4
Operating system:   Debian Linux 8 / Redhat Linux 6.5
Description:        

Hi,

I run a web server with high loads ~ 700 users / minute.

Sometimes (rare) I get an error like duplicate value violation on insert on
field "search_term".

Table is like:
id, primary key
search_term, varchar(255), UNIQUE

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.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #13496: INSERT WHERE NOT EXISTS error
  2015-07-09 15:53 BUG #13496: INSERT WHERE NOT EXISTS error ilies.ovidiu@googlemail.com
@ 2015-07-09 16:53 ` David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: David G. Johnston @ 2015-07-09 16:53 UTC (permalink / raw)
  To: ilies.ovidiu@googlemail.com; +Cc: pgsql-bugs

On Thu, Jul 9, 2015 at 11:53 AM, <ilies.ovidiu@googlemail.com> wrote:

> The following bug has been logged on the website:
>
> Bug reference:      13496
> Logged by:          Radu Ovidiu
> Email address:      ilies.ovidiu@googlemail.com
> PostgreSQL version: 9.4.4
> Operating system:   Debian Linux 8 / Redhat Linux 6.5
> Description:
>
> Hi,
>
> I run a web server with high loads ~ 700 users / minute.
>
> Sometimes (rare) I get an error like duplicate value violation on insert on
> field "search_term".
>
> Table is like:
> id, primary key
> search_term, varchar(255), UNIQUE
>
> 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.
>

​You are correct; but this is not a bug.

If you have an actual question you should post in at:

pgsql-general@postgresql.org

David J.
​

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #13496: INSERT WHERE NOT EXISTS error
  2015-07-09 15:53 BUG #13496: INSERT WHERE NOT EXISTS error ilies.ovidiu@googlemail.com
@ 2015-07-09 16:54 ` hubert depesz lubaczewski <depesz@depesz.com>
  1 sibling, 0 replies; 3+ messages in thread

From: hubert depesz lubaczewski @ 2015-07-09 16:54 UTC (permalink / raw)
  To: ilies.ovidiu@googlemail.com; +Cc: pgsql-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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-07-09 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-07-09 15:53 BUG #13496: INSERT WHERE NOT EXISTS error ilies.ovidiu@googlemail.com
2015-07-09 16:53 ` David G. Johnston <david.g.johnston@gmail.com>
2015-07-09 16:54 ` hubert depesz lubaczewski <depesz@depesz.com>

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