I have the following INDEX on table a:
SHOW INDEX FROM a
Table, Non_unique, Key_name, Seq_in_index, Column_name, Collation, Cardinality, Sub_part, Packed, Null, Index_type, Comment, Index_comment
a, '1', 'oc_id', '1', 'OC_ID', 'A', '19', NULL, NULL, 'YES', 'BTREE', '', ''
And the explain
plan shows it's being used:
EXPLAIN SELECT * FROM a
WHERE OC_ID IN (
5841)
'1', 'SIMPLE', a, 'ref', 'oc_id,oc1', 'oc_id', '6', 'const', '121080', 'Using where'
But using a subquery it's not used:
EXPLAIN SELECT * FROM a
WHERE OC_ID IN (SELECT OC_ID FROM b WHERE tteci = "54301")
'1', 'PRIMARY', a, 'ALL', NULL, NULL, NULL, NULL, '701145408', 'Using where'
'2', 'DEPENDENT SUBQUERY', b, 'index_subquery', 'OC_ID,tteci1', 'OC_ID', '6', 'func', '1', 'Using where'
What am I doing wrong?
a
andb
on OC_ID and filterb
on tteci). Then either 1) MySQL will "be happy" and select the desired index, or 2) the question will be different as the subquery is no longer relevant / existing. – user2864740SHOW CREATE TABLE
. – Rick James