Mysql deadlock caused by INSERT… ON DUPLICATE KEY UPDATE

What is a deadlock and what conditions cause deadlock? A deadlock is a state in which each member of a group is waiting for another member. An example of deadlock is the dining philosophers problem. Each philosopher will pick up the left fork and wait for the right fork to become available, but it never does. This week, I encountered mysql deadlock when running multiple “INSERT… ON DUPLICATE KEY UPDATE” queries on the database. With a single connection, this insertion works perfectly. However, with multiple connections, it creates a deadlock issue. Below is a summary of what happened.......

The constant space tree traversal algorithm: Morris Traversal

What is Morris Traversal? Morris Traversal is an algorithm that allows us to traverse the tree without using a stack or recursion. That means we can traverse the tree with O(n) time complexity and O(1) space complexity. The usual method of using stack or recursion to traverse the tree would require O(h) space, with h being the height of the tree, with worst case space complexity of O(n). Basically Morris Traversal makes sense if we have a fat tree and we want to be economical on space usage. How does it work? The essence of the algorithm is to build a bridge between the root, and its predecessor in its left subtree for the first time, and then remove this bridge when we traverse to the predecessor for the second time.......

Me, a millennial, learning Vim from scratch

If you are like me, you probably asked yourself "How to exit Vim?" at some point in your life. So you probably have tried hitting that Esc, it doesn't work. Ok what about the good old Ctrl + C... it doesn't respond. Type quit + enter? Well, it does type "quit" with a new line 😅 It turns out that this is a common question, because literally over one million developers have asked this question! Good to know that we are part of this global developer confusion right? So how did I start learning it? I had the same confusion for the first 21 years of my life.......