Avoiding full table scan when performing inner joins in MySQL using IN in WHERE clause -
how can avoid full table scan when performing inner joins in mysql using in in clause? example:
explain select -> count(distinct(n.nid)) -> node n -> inner join term_node tn on n.nid = tn.nid -> inner join content_type_article ca on n.nid = ca.nid -> tn.tid in (67,100) -> ; +----+-------------+-------+--------+----------------------------------+---------+---------+----------------------+-------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | | +----+-------------+-------+--------+----------------------------------+---------+---------+----------------------+-------+--------------------------+ | 1 | simple | tn | | primary,nid | null | null | null | 42180 | using | | 1 | simple | ca | ref | nid,field_article_date_nid_index | nid | 4 | drupal_mm_qas.tn.nid | 1 | using index | | 1 | simple | n | eq_ref | primary | primary | 4 | drupal_mm_qas.ca.nid | 1 | using where; using index | +----+-------------+-------+--------+----------------------------------+---------+---------+----------------------+-------+--------------------------+ 3 rows in set (0.00 sec)
it seems you're filtering column mysql identified not selective enough. when filter's cardinality low (i.e, number of distinct rows filter low), mysql thinks, of time accurately, fts faster.
to confirm, please show result of select count(distinct tn.tid) term_node tn , select count(*) term_node tn
Comments
Post a Comment