I have some servers. Some of them have ips assigned. I want to figure out how many do not. There are clearly more servers than have ips assigned, but my db tells me there are no servers that have no ips assigned...
I'm at my wit's end here. Is my DB corrupted in some strange way?
SELECT COUNT(*)
FROM server
...returns:
+----------+
| count(*) |
+----------+
| 23088 |
+----------+
1 row in set (0.00 sec)
This:
SELECT COUNT(*)
FROM server
WHERE server_id IN (SELECT DISTINCT(server_id)
FROM ips)
...returns:
+----------+
| count(*) |
+----------+
| 13811 |
+----------+
1 row in set (0.01 sec)
This:
SELECT COUNT(*)
FROM server
WHERE server_id NOT IN (SELECT DISTINCT(server_id)
FROM ips);
...returns:
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.02 sec)
Results have been edited to protect the guilty, but you get the idea.
- All tables are InnoDB.
Check table
returns ok on both of these tables.
EDIT: thank you for the suggestion of using LEFT JOIN
. This definitely confirms that the problem is the MySQL bug.
mysql> SELECT count(s.server_id) FROM server s LEFT JOIN ips i on s.server_id = i.server_id WHERE i.server_id IS NULL;
+--------------------+
| count(s.server_id) |
+--------------------+
| 9277 |
+--------------------+
1 row in set (0.04 sec)
Since 9277 + 13811 = 23088, this means that all servers without ips + all servers with ips does indeed == all servers.
I've scheduled an upgrade of the mysql server for beginning of next week. Stay tuned.