deadlock prevention - enforce locking order
I have a situation where 2 different logic flows lock/update the same logical structure. The structure consists of a hierarchy of 2 tables with multiple rows to lock. The application logic flows use different SQL statements but tries to lock the tables in the same order. The assumption is you have control over the order in which the logical rows are locked by using the ORDER BY and FOR UPDATE syntax.
For example, FLIGHT->SEGMENT->LEG (an Airline application where a flight is broken down into segments and legs of a flight)
SQL for flow #1
select <segment information> from segment where flightid=?