Updating comments in a modified preorder tree traversal. Do I need to lock the rows?

114 views Asked by At

Your basic comment/reply system sorted with the premodified tree traversal. Sample output could look like this:

CommentA
    SubcommentA-1
            SubcommentA1-1
    SubcommentA-2
CommentB

And so forth. When a user makes a comment then all the appropriate left and right values are updated. My thought is if you have multiple replies at the same time, then the numbers could get all out of whack. I am not super familiar with mysql and I know there is row locking so that means that that kind of problem can definitely happen in some kind of context. I'm just not sure if this is that kind of context. If I should lock it I am guessing I will want to do some form of SELECT x FROM table FOR UPDATE; UPDATE table SET "the stuff needed setting"; If I should do that, should I select all of the rows (lft=1 and rgt=max)? Or should I only select what will be updated?

0

There are 0 answers