Assuming your database is running with default settings, I am more surprised that your SELECT will ever return two different values.
The documentation says this
If the transaction isolation level is REPEATABLE READ (the default level), all consistent reads within the same transaction read the first snapshot, such as a read in that transaction. You can get a more recent snapshot for your requests by completing the current transaction and then issuing new requests.
So, if the default isolation level REPEATABLE READ is valid, I expect all queries to return data that matches the state of the database at the time of the first query.
However, it seems that this may help.
With READ COMMITTED isolation level, each sequential read within a transaction sets and reads its own fresh snapshot.
I think you should try
$O_dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED');
immediately after connecting, and see if this fixes something for you.
However, after this transaction, you must make sure that you either disconnect the database handler or return it to the previous isolation level. Otherwise, you will start to get conflicting results.
source share