Hello Guys
I have a mysql 5.7 performing almost ( Full Table scan ) on the select below.
So, I have a question. If I have the indexes below why have I getting full table scan on table cp_rawcdr
?
Shoud I create composite Index with all columns ???
Ps ; I have already performed analyze in both tables and I can’t use hints on this query
PRIMARY KEY (`id`),
KEY `cp_rawcdr_network_id_47a232398250b37d_fk_cp_network_id` (`network_id`),
KEY `cp_rawcdr_date_sent` (`date`,`sent`),
KEY `cp_rawcdr_sim_card_id_sent` (`sim_card_id`,`sent`),
mysql> explain
-> SELECT `cp_rawcdr`.`id` , `cp_rawcdr`.`sim_card_id`, `cp_rawcdr`.`date`, `cp_rawcdr`.`end_date`, `cp_rawcdr`.`duration`, `cp_rawcdr`.`network_id`, `cp_rawcdr`.`type`, `cp_rawcdr`.`sent`,
-> `cp_rawcdr`.`external_correlation_id`, `cp_rawcdr`.`b_party_number`
-> FROM `cp_rawcdr`
-> WHERE ((`cp_rawcdr`.`sim_card_id`) IN (SELECT U0.`id` FROM `cp_simcard` U0 WHERE U0.`organization_id` = 4039) AND `cp_rawcdr`.`sent` = 0)
-> Order By `cp_rawcdr`.`id`;
+----+-------------+-----------+------------+--------+--------------------------------------------------------------------------+---------+---------+------------------------------+-----------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+------------+--------+--------------------------------------------------------------------------+---------+---------+------------------------------+-----------+----------+-------------+
| 1 | SIMPLE | cp_rawcdr | NULL | index | cp_rawcdr_sim_card_id_sent | PRIMARY | 4 | NULL | 672525897 | 10.00 | Using where |
| 1 | SIMPLE | U0 | NULL | eq_ref | PRIMARY,cp_simcar_organization_id_53ac94325583cf1e_fk_cp_organization_id | PRIMARY | 4 | trum2m.cp_rawcdr.sim_card_id | 1 | 39.26 | Using where |
+----+-------------+-----------+------------+--------+--------------------------------------------------------------------------+---------+---------+------------------------------+-----------+----------+-------------+
2 rows in set, 1 warning (0.00 sec)
mysql>