I get a "Range checked for each record (index map: 0x1)" in EXPLAIN SELECT when doing an INNER JOIN on a PRIMARY key with 2 values (using either IN or OR constructs)
Here is the query:
SELECT *
FROM message AS m
INNER JOIN user AS u
ON u.id = m.sender_id OR u.id = m.receiver_id
When doing an explain, it gives me:
+----+-------------+-------+------+---------------+------+---------+------+-------+-----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+-------+-----------------------------------------------+
| 1 | SIMPLE | u | ALL | PRIMARY | null | null | null | 75000 | Range checked for each record (index map: 0x1)|
+----+-------------+-------+------+---------------+------+---------+------+-------+-----------------------------------------------+
It can't be...
If I try this I get the same result:
SELECT *
FROM message AS m
INNER JOIN user AS u
ON u.id IN(m.sender_id, m.receiver_id)
But if I do this, it works fine and I get only 1 row parsed:
SELECT *
FROM message AS m
INNER JOIN user AS u
ON u.id = m.sender_id
How is this possible? I'm joining on a primary key with same-type values. (the actual query is "a bit" more complicated but nothing fancy, 2 inner joins and lastly one left join)
It should be 2 rows, period.
Thanks for any input on this (did some research but did not find anything valuable except for "please add an index", which is obviously not applicable here)
EDIT: yes, I tried the USE INDEX statement, but still no luck
EDIT: Here is a very simple schema to reproduce this weird behavior of MySQL:
CREATE TABLE test_user (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
PRIMARY KEY (id)
);
CREATE TABLE test_message (
id INT NOT NULL AUTO_INCREMENT,
sender_id INT NOT NULL,
receiver_id INT NOT NULL,
PRIMARY KEY (id),
INDEX idx_sender (sender_id),
INDEX idx_receiver (receiver_id)
);
EXPLAIN SELECT *
FROM test_message AS m
INNER JOIN test_user AS u
ON u.id = m.sender_id OR u.id = m.receiver_id;
FULL OUTER JOIN
. And there is no such thing in SQL asFULL INNER JOIN
. – SneakerEXPLAIN
-- The query mentions two tables; theEXPLAIN
mentions only one. Please fix. – Tillis