0

I had been working on "Preorder tree traversal algorithm" as a part of my daily task. What I came across was that for MySQL, we need to lock a table and after insertion or deletion of any entry, we need to unlock the particular table (I succeeded in my task though).... I just wonder why we do this? Apart from this case, where else do you think this can be used in case its frequently in use ?

3
  • I hope I am clear enough Commented Jan 8, 2010 at 14:26
  • 1
    To be honest, you could be clearer by properly spelling words like "juz", starting your sentences with a capital letter, and ending your sentences with a single period or question mark. Commented Jan 8, 2010 at 15:26
  • ok Bart, I will definitely make things clearer the next time onwards. Commented Jan 9, 2010 at 4:30

1 Answer 1

1

You need to lock a table if you don't want its contents to change while you are doing whatever you are.

So in your case, I assume that you would not want the table to change while you do your traversal (I assume your table data forms some sort of tree).

So one option you have is: LOCK the table, COPY its contents to another table, UNLOCK it, and operate on the copy.

If your original table is small enough, you can even make your temp table in-memory.

Beware: locking tables can cause other scripts that use the table to wait! Be sure that your operations will not take a lot of time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.