This is the subquery:
NOT EXISTS (SELECT *
from media_actions m_a
WHERE m.user_id = 19 AND m_a.ig_media_id = m.ig_media_id
)
You can speed this up with an index:
create index idx_media_actions on media_actions(ig_media_id, user_id)
You can also phrase this as:
NOT EXISTS (SELECT 1
from media_actions m_a
WHERE m.user_id = 19 AND m_a.ig_media_id = m.ig_media_id
)
However, I think MySQL is smart enough to ignore the *
in such a subquery.