SQL, multithreading, and logging changes