mysql - Does last_insert_id return the correct auto_increment id in a multiprocessing environment? -
here's simplified code in web application:
sub insert { $pid = fork(); if ($pid > 0) { return; } else { &insert_to_mysql(); $last_id = &get_last_inserted(); # call mysql last_inserted_id exit(0); } } $i (1..10) { &insert(); }
since insert
called in multiprocessing environment, order of get_last_inserted
might uncertain. return correct last id corresponding insert_to_mysql
subroutine? read documents saying long processes don't share same mysql connection, returned id right one. however, these processes spawned same session, i'm not sure if share mysql connection or not. in advance.
these processes spawned same session
are saying you're forking , using same connection in more 1 process? doesn't work @ all, never mind last_insert_id()
. can't have 2 processes reading , writing same connection! response 1 end in other, assuming 2 clients didn't clobber each other's request.
does last_insert_id return correct auto_increment id in multiprocessing environment?
according mysql's documentation last_insert_id()
,
the id generated maintained in server on per-connection basis.
it useless otherwise. since connections can't shared across processes, yes, it's safe.
Comments
Post a Comment