PRIMARY KEY (`id`), KEY `sort1` (`thread`,`id`), KEY `idx_r` (`id_user_r`), KEY `idx_s` (`id_user_s`)? That would be great, because we wouldn't have to ALTER anything.
+----+--------------+------------+--------+---------------+---------+---------+------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------+------------+--------+---------------+---------+---------+------+------+---------------------------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 6 | Using temporary; Using filesort | | 1 | PRIMARY | m | eq_ref | PRIMARY | PRIMARY | 8 | x.id | 1 | | | 2 | DERIVED | messages | index | sort1,idx_s | PRIMARY | 8 | NULL | 2 | Using where | | 3 | UNION | messages | index | sort1,idx_r | PRIMARY | 8 | NULL | 2 | Using where | | NULL | UNION RESULT | <union2,3> | ALL | NULL | NULL | NULL | NULL | NULL | | +----+--------------+------------+--------+---------------+---------+---------+------+------+---------------------------------+ 5 rows in set (0.03 sec)
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.