locks ను ఒక consistent global order లో acquire చేయండి, transactions ను చిన్నగా ఉంచండి, safe అయిన చోట isolation ను తగ్గించండి, మరియు deadlock ఇంకా జరిగినప్పుడు loser ను retry చేయండి. ఒక deadlock ఒక cycle: transaction A row 1 ను hold చేసి row 2 కోసం వేచి ఉంటుంది, B row 2 ను hold చేసి row 1 కోసం వేచి ఉంటుంది — ఏదీ ముందుకు సాగలేదు, కాబట్టి DB ఒకదాన్ని kill చేస్తుంది.
మీరు break చేయాల్సిన cycle
Tx A Tx B
holds row 1 ──── waits ────▶ row 2 (held by B)
▲ │
│ waits │ holds
└────────── row 1 ◀────────────┘
(cycle = deadlock; DB aborts one victim)
