SELECT 
  DISTINCT pc.category_id, 
  count(DISTINCT pc.product_id) as total_products 
FROM 
  tmall_products AS products 
  LEFT JOIN tmall_products_categories AS pc ON products.product_id = pc.product_id 
WHERE 
  1 
  AND products.product_id IN (228, 229, 205, 206, 207) 
GROUP BY 
  pc.category_id

Query time 0.00759

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.110742806,
    "filesort": {
      "sort_key": "pc.category_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "products",
              "access_type": "range",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "loops": 1,
              "rows": 5,
              "cost": 0.003922077,
              "filtered": 100,
              "attached_condition": "products.product_id in (228,229,205,206,207)",
              "using_index": true
            }
          },
          {
            "table": {
              "table_name": "pc",
              "access_type": "ref",
              "possible_keys": ["pt"],
              "key": "pt",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["tmall.products.product_id"],
              "loops": 5,
              "rows": 11,
              "cost": 0.071212957,
              "filtered": 100
            }
          }
        ]
      }
    }
  }
}

Result

category_id total_products
170 2
171 3