mysql - massive join does not use indexes -
mysql - massive join does not use indexes -
i have table tbl_ratings 100 1000000 records. each record rating user on item. think of whole bunch of item vectors, each vector containing rating @ user_id dimensions. goal compute average difference between every pair of vectors (on matching dimensions). trying bring together onto itself, reason ignoring both of indexes.
create table tbl_ratings ( user_id mediumint unsigned not null, item_id mediumint unsigned not null, rating tinyint not null, unique key user_index (user_id,item_id,rating) using hash, unique key item_index (item_id,user_id,rating) using hash ) engine=memory; explain select a.item_id active_id, n.item_id neighbor_id, avg(a.rating-n.rating) intercept, count(a.rating) overlap tbl_ratings # active vectors bring together tbl_ratings n # neighbour vectors on a.user_id=n.user_id grouping a.item_id, n.item_id \g *************************** 1. row *************************** id : 1 select_type : simple table : type : possible_keys: user_index key : null key_len : null ref : null rows : 100480507 : using temporary; using filesort *************************** 2. row *************************** id : 1 select_type : simple table : n type : possible_keys: user_index key : null key_len : null ref : null rows : 100480507 : using where; using bring together buffer (block nested loop)
as others have said, either alter btree index (of user_id first field, entries user cluster together), or utilize non-unique hash index on user_id bring together field. there no other option.
mysql sql
Comments
Post a Comment