We’re seeing this behavior randomly on newly inserted records and only on the production database (Amazon’s RDS). Looks like something related to a deadlock… (no errors reported)
The affected tables are InnoDB, payment_id is auto-increment and all transaction end-times are in the order of milliseconds. All the connections are on the same server, autocommit is enabled and there is no replication (as far as Amazon’s documentation).
Connection #1:
2011-03-07 14:09:54 INSERT INTO payments SET payment_transaction = ‘XYZ’
Connection #2:
2011-03-07 14:10:06: SELECT * FROM payments WHERE
payment_transaction= ‘XYZ’ LIMIT 0, 1
Response: empty
2011-03-07 14:10:06: SELECT * FROM payments ORDER BY
payment_idDESC LIMIT 0, 1
Response: [payment_id] => 26242, [payment_transaction] => ABC
2011-03-07 14:50:06: SELECT * FROM payments WHERE
payment_transaction= ‘XYZ’ LIMIT 0, 1
Response: [payment_id] => 26243, [payment_transaction] => XYZ
By adding some debug points to the application I noted that these (randomly problematic) INSERTs are actually taking around 50+ seconds to complete (in contrast to what the log was saying). So to anyone having this issue, make sure you benchmark the start and end times of the INSERT within your application environment.