I created this table:
CREATE TABLE incident_originator (
id_incident INT (11) UNSIGNED NOT NULL,
id_user INT (11) NOT NULL,
PRIMARY KEY (
id_incident,
id_user
),
CONSTRAINT fk_incident_incident_originator FOREIGN KEY (id_incident) REFERENCES incident_table (id_incident) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT fk_user_incident_originator FOREIGN KEY (id_user) REFERENCES users (id_user) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Yet, the fk_user_incident_originator
, is indexed, and the fk_incident_incident_originator
is not. Why is that? Isn't InnoBD supposed to automatically index all foreign keys? The lack of an index in the id_incident
would make joins slower, wouldn't it? The more I read, the less I understand...
Plus, when I add values to the table, they are ordered by the second column and it gets weird to read as a human being.
EDIT: When I do a SHOW INDEX FROM incident_originator;
it returns this:
Non_unique Key_name Seq_in_index Column_name
0 PRIMARY 1 id_incident
0 PRIMARY 2 id_user
1 fk_user_incident_originator 1 id_user