SELECT 
  products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      products_categories.link_type = "M", 
      CONCAT(
        products_categories.category_id, 
        "M"
      ), 
      products_categories.category_id
    )
  ) AS category_ids 
FROM 
  products_categories 
  INNER JOIN categories ON categories.category_id = products_categories.category_id 
  AND categories.storefront_id IN (0, 1) 
  AND (
    categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, categories.usergroup_ids) 
    OR FIND_IN_SET(1, categories.usergroup_ids)
  ) 
  AND categories.status IN ('A', 'H') 
WHERE 
  products_categories.product_id IN (
    223931, 223968, 224015, 223958, 223988, 
    223974, 223967, 223981, 224021, 223935, 
    224043, 224018, 223964, 223955, 224023, 
    223949, 223998, 223962, 223934, 223977, 
    224011, 223996, 223994, 223975, 224024, 
    223932, 223952, 224014, 224026, 223970, 
    224013, 223963, 224042, 223933, 223937, 
    223971, 223954, 223960, 223987, 223984, 
    223966, 223978, 223993, 224027, 223948, 
    224036, 224038, 224046
  ) 
GROUP BY 
  products_categories.product_id

Query time 0.00128

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "26.71"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 48,
            "rows_produced_per_join": 48,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "5.11",
              "eval_cost": "4.80",
              "prefix_cost": "9.91",
              "data_read_per_join": "768"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`goimagine`.`products_categories`.`product_id` in (223931,223968,224015,223958,223988,223974,223967,223981,224021,223935,224043,224018,223964,223955,224023,223949,223998,223962,223934,223977,224011,223996,223994,223975,224024,223932,223952,224014,224026,223970,224013,223963,224042,223933,223937,223971,223954,223960,223987,223984,223966,223978,223993,224027,223948,224036,224038,224046))"
          }
        },
        {
          "table": {
            "table_name": "categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "goimagine.products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "12.00",
              "eval_cost": "0.24",
              "prefix_cost": "26.71",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`goimagine`.`categories`.`storefront_id` in (0,1)) and ((`goimagine`.`categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`goimagine`.`categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`goimagine`.`categories`.`usergroup_ids`))) and (`goimagine`.`categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
223931 2566M
223932 2566M
223933 2566M
223934 2566M
223935 2566M
223937 2566M
223948 2566M
223949 2566M
223952 2566M
223954 2566M
223955 2566M
223958 2566M
223960 2566M
223962 2566M
223963 2566M
223964 2566M
223966 2566M
223967 2566M
223968 2566M
223970 2566M
223971 2566M
223974 2566M
223975 2566M
223977 2566M
223978 2566M
223981 2566M
223984 2566M
223987 2566M
223988 2566M
223993 2566M
223994 2566M
223996 2566M
223998 2566M
224011 2566M
224013 2566M
224014 2566M
224015 2566M
224018 2566M
224021 2566M
224023 2566M
224024 2566M
224026 2566M
224027 2566M
224036 2566M
224038 2566M
224042 2566M
224043 2566M
224046 2566M