Handling and Optimizing Transactions in MySQL