News for hackers. Stuff that matters.
Re:Scaling Databases at Activision [pdf] by berkle4455 on Friday April 21, 2023 @06:08PM (#35660902)
Using transactions or UUID/ULIDs though maybe I’m misunderstandingyour question. How do foreign key constraints help with concurrency?
Re:Scaling Databases at Activision [pdf] by AlisdairO on Friday April 21, 2023 @06:26PM (#35661070)
Table User: userid, etc

Table Resources: resourceid, userid, etc

If I want to restrict deletion of a user to only be possible after all the resources are deleted, I'm forced into using higher-than-default isolation levels in most DBs. This has significant performance implications. It's also much easier to make a mistake - for example, if when creating a resource I check that the user exists prior to starting the transaction, then start the tran, then do the work, it will allow insertion of data into a nonexistent user.

Re:Scaling Databases at Activision [pdf] by edf13 on Saturday April 22, 2023 @02:40AM (#35663979)
Add your user check as a where clause on the resources insert?
Re:Scaling Databases at Activision [pdf] by AlisdairO on Saturday April 22, 2023 @10:47AM (#35667087)
Can you give an example? I’m not aware of a mechanism like that that will protect you from concurrency artifacts reliably - certainly not a general one.
Re:Scaling Databases at Activision [pdf] by drwiggly on Saturday April 22, 2023 @04:48PM (#35670784)
start transaction;

select id from users where id = ? for update;

if row_count() < 1 then raise 'no user' end if;

insert into sub_resource (owner, thing) values (?, ?);

commit;

??

Re:Scaling Databases at Activision [pdf] by AlisdairO on Saturday April 22, 2023 @06:40PM (#35671559)
Do that in most relational dbs in the default isolation level (read committed), and concurrently executing transactions will still be able to delete users underneath you after the select.

If we take postgres as an example, performing the select takes exactly zero row level locks, and makes no guarantees at all about selected data remaining the same after you’ve read it.