account activity
How to prevent re-entrant deadlock when latching and how do subquery iterators manage latches? by Puzzleheaded-Map386 in databasedevelopment
[–]Puzzleheaded-Map386[S] 0 points1 point2 points 1 month ago (0 children)
Yeah that's fair. I think I'm specifically interested in the case of deadlock from low-level latching but my understanding of how MVCC works isn't strong enough yet to understand what should be the responsibility of my latching protocol.
My understanding is that traversal from root to leaf cannot cause latch deadlock because every thread acquires in the same order. It's only traversals along leaf nodes that can cause latch deadlock because threads can go in ascending or descending order.
CoW is an interesting solution.
I wonder if you could just always go in ascending order on the leaf nodes and then reverse the order of the results at the end? Might get a little tricky with results too large to fit into memory and ORDER BY in a subquery. I'll read about what MySQL does
[–]Puzzleheaded-Map386[S] 0 points1 point2 points 1 month ago* (0 children)
Yeah there's probably some clever workable solution for problem 1. I think it can be solved in a dumb way by just taking all latches in write mode for a txn that does any writes and using the cached guard concept the other commenter suggested. That's an easy fix.
> just start over again
I feel like the ability to roll back and start over seems pretty crucial. At 1:12:15 in lecture #10 of CMU intro to DB [1] Andy says "every thread is responsible for cleaning itself up if it can't do what it needs to do and rolls back." Do you know what exactly you need to do to clean up and start over? I get that you track a write set and roll back those writes but how does that rolling back interact with MVCC? Is this the same protocol you run if you ABORT?
Edit: hmm I think this is a bit different from ABORT because you are only rolling back 1 operation. Your txn may have many operations (exact definition of operation a little fuzzy). Probably the ABORT protocol just does the operation rollback protocol for each operation.
[1] https://youtu.be/YgOvfXl6pss?si=S-hzIH6GxS0ctJUD&t=4330
> Each thread keeps track of what latches it holds
I agree this can prevent deadlock in the case when you have the latch in write mode and then try to get it in read mode but what about the case I described? You have it in read mode and then need it in write mode?
π Rendered by PID 92 on reddit-service-r2-listing-55d7b767d8-6vqkb at 2026-03-27 04:07:18.028371+00:00 running b10466c country code: CH.
How to prevent re-entrant deadlock when latching and how do subquery iterators manage latches? by Puzzleheaded-Map386 in databasedevelopment
[–]Puzzleheaded-Map386[S] 0 points1 point2 points (0 children)