MySQL Occasionally Returns Wrong Value
This is a general question, one that I've been scratching my head on for a
while now. My company's database handles about 2k rows a day. 99.9% of the
time, we have no problem with the values that are returned in the
different SELECT statements that are set up. However, on a very rare
occasion, our database will "glitch" and return the value for a completely
different row than what was requested.
This is a very basic example:
+---------+-------------------------+
| row_id | columnvalue |
+---------+-------------------------+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
+---------+-------------------------+
SELECT columnvalue FROM table_name WHERE row_id = 1 LIMIT 1
Returns: 10
But on the very rare occasion, it may return: 20, or 30, etc.
I am completely baffled as to why it does this sometimes and would
appreciate some insight on what appears to be a programming phenomena.
More specific information:
SELECT
USERID, CONCAT( LAST, ', ', FIRST ) AS NAME, COMPANYID
FROM users, companies
WHERE users.COMPANYCODE = companies.COMPANYCODE
AND USERID = 9739 LIMIT 1
mysql> DESCRIBE users;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| USERID | int(10) | NO | PRI | NULL | auto_increment |
| COMPANYCODE| int(10) | NO | MUL | | |
| FIRST | varchar(255)| NO | MUL | | |
| LAST | varchar(255)| NO | MUL | | |
+------------+-------------+------+-----+---------+----------------+
mysql> DESCRIBE companies;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| COMPANYID | int(10) | NO | PRI | NULL | auto_increment |
| COMPANYCODE| varchar(255)| NO | MUL | | |
| COMPANYNAME| varchar(255)| NO | | | |
+------------+-------------+------+-----+---------+----------------+
What the results were suppose to be: 9739, "L----, E----", 2197 What the
results were instead: 9739, "L----, E----", 3288
Basically, it returned the wrong company id based off the join with
companycode. Given the nature of our company, I can't share any more
information than that.
I have run this query 5k times and have made very modification to the code
imaginable in order to generate the second set of results and I have no
been able to duplicate it. I'm not quick to blame MySQL -- this has been
happening (though rarely) for over 8 years, and have exhausted all other
possible causes. I have suspected the results were manually changed after
the query was ran, but the timestamps states otherwise.
I'm just scratching my head as to why this can run perfectly 499k out of
500k times.
No comments:
Post a Comment