Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Mysql using the wrong index?
    primarykey
    data
    text
    <p>Mysql is using an index on (faver_profile_id,removed,notice_id) when it should be using the index on (faver_profile_id,removed,id). The weird thing is that for some values of faver_profile_id it does use the correct index. I can use FORCE INDEX which drastically speeds up the query, but I'd like to figure out why mysql is doing this. </p> <p>This is a new table (35m rows) copied from another table using INSERT INTO.. SELECT FROM. I did not run OPTIMIZE TABLE or ANALYZE after. Could that help?</p> <pre><code>SELECT `Item`.`id` , `Item`.`cached_image` , `Item`.`submitter_id` , `Item`.`source_title` , `Item`.`source_url` , `Item`.`source_image` , `Item`.`nudity` , `Item`.`tags` , `Item`.`width` , `Item`.`height` , `Item`.`tumblr_id` , `Item`.`tumblr_reblog_key` , `Item`.`fave_count` , `Item`.`file_size` , `Item`.`animated` , `Favorite`.`id` , `Favorite`.`created` FROM `favorites` AS `Favorite` LEFT JOIN `items` AS `Item` ON ( `Favorite`.`notice_id` = `Item`.`id` ) WHERE `faver_profile_id` =11619 AND `Favorite`.`removed` =0 AND `Item`.`removed` =0 AND `nudity` =0 ORDER BY `Favorite`.`id` DESC LIMIT 26 </code></pre> <p><b>Query execution plan:</b> "idx_notice_id_profile_id" is an index on (faver_profile_id,removed,notice_id)</p> <pre><code>1 | SIMPLE | Favorite | ref | idx_faver_idx_id,idx_notice_id_profile_id,notice_id_idx | idx_notice_id_profile_id | 4 | const,const | 15742 | Using where; Using filesort | 1 | SIMPLE | Item | eq_ref | PRIMARY | PRIMARY | 4 | gragland_imgfave.Favorite.notice_id | 1 | Using where </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload