Tuesday 28 August 2018

Query MySQL does not return the newly inserted record

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_id DESC 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

Its depend in what function you are using if undertand you, to see how many row effected by SELECT instruction use mysql_num_rows(), use mysql_affected_rows()with DELETE, UPDATE qnd INSERT instructions according to this.

0 comments:

Post a Comment