Timeline for Best practice regarding concurrency for INSERT into a table with composite primary key?
Current License: CC BY-SA 3.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 15, 2020 at 9:05 | history | edited | CommunityBot | Commonmark migration | |
| Apr 13, 2017 at 12:42 | history | edited | CommunityBot | replaced http://dba.stackexchange.com/ with https://dba.stackexchange.com/ | |
| Oct 30, 2015 at 23:43 | comment | added | Pieter-Jan Vandenbussche | @ErwinBrandstetter Yep, that's what I mean, sorry if I didn't clarify it correctly. Oh and btw, regarding your other comment, I'm a student, not a teach or anything :) | |
| Oct 30, 2015 at 23:43 | comment | added | Pieter-Jan Vandenbussche | @JoishiBodio Basically what I mean is, say there's about 3 people on a team authorized to add an existing user to a team. They execute a PUT request to e.g. /teams/1/users/2 (adding user with ID 2 to team with ID 1 in junction table teams_users). If that specific relation is already in the table, it'll throw a duplicate key exception. My question is, how do I optimally deal with that? I'm afraid that when using option 1 or 2, another user that's authorized to add a user to a team will magically at the exact same time add that specific user as well, resulting in a race condition. | |
| Oct 30, 2015 at 11:52 | history | tweeted | twitter.com/StackDBAs/status/660061811568418816 | ||
| Oct 30, 2015 at 2:24 | history | edited | Erwin Brandstetter | CC BY-SA 3.0 | shorten title, trim noise, clarify, clean up |
| Oct 30, 2015 at 2:13 | answer | added | Erwin Brandstetter | timeline score: 2 | |
| Oct 30, 2015 at 1:59 | comment | added | Erwin Brandstetter | If I wanted to add a user to a team .. This assumes an existing user and only INSERT INTO teams_users ... is your topic, right? | |
| Oct 29, 2015 at 19:54 | history | edited | Erik | CC BY-SA 3.0 | deleted 61 characters in body |
| Oct 29, 2015 at 19:09 | answer | added | Joishi Bodio | timeline score: 1 | |
| Oct 29, 2015 at 19:07 | comment | added | Joishi Bodio | Also .. what are you trying to achieve from a concurrency standpoint?.. Do you have 3 threads running each doing a single INSERT? Are they sharing the same database connection, or do they have their own?.. | |
| Oct 29, 2015 at 19:05 | comment | added | Joishi Bodio | Not sure I understand the difference between your listed Option 2 and Option 3 .... typically one does a WHERE EXISTS in inserting if they're doing an UPSERT operation, but an actual UPSERT operation is not available. (UPSERT = IF EXISTS, UPDATE, ELSE INSERT) | |
| Oct 29, 2015 at 19:03 | review | First posts | |||
| Oct 29, 2015 at 19:54 | |||||
| Oct 29, 2015 at 19:02 | history | asked | Pieter-Jan Vandenbussche | CC BY-SA 3.0 |