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 (
    187599, 79185, 79358, 82647, 82677, 
    82659, 82664, 82650, 79359, 82662, 
    80067, 82658, 189127, 191122, 197476, 
    82675, 83702, 82663, 199702, 188170, 
    187601, 191601, 188620, 201635, 82665, 
    191770, 82674, 210711, 203577, 82670, 
    169289, 153234, 259182, 259310, 269097, 
    247890, 269118, 247892, 269100, 269096, 
    269091, 269090, 247902, 259643, 269113, 
    247897, 258388, 269098, 269093, 269116, 
    259598, 269111, 269107, 269108, 259655, 
    269094, 269095, 204373, 283319, 292893, 
    283328, 284130, 306484, 269110, 306494, 
    269106
  ) 
GROUP BY 
  products_categories.product_id

Query time 0.00274

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "135.11"
    },
    "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": 245,
            "rows_produced_per_join": 245,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "24.86",
              "eval_cost": "24.50",
              "prefix_cost": "49.36",
              "data_read_per_join": "3K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`goimagine`.`products_categories`.`product_id` in (187599,79185,79358,82647,82677,82659,82664,82650,79359,82662,80067,82658,189127,191122,197476,82675,83702,82663,199702,188170,187601,191601,188620,201635,82665,191770,82674,210711,203577,82670,169289,153234,259182,259310,269097,247890,269118,247892,269100,269096,269091,269090,247902,259643,269113,247897,258388,269098,269093,269116,259598,269111,269107,269108,259655,269094,269095,204373,283319,292893,283328,284130,306484,269110,306494,269106))"
          }
        },
        {
          "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": 12,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "61.25",
              "eval_cost": "1.23",
              "prefix_cost": "135.11",
              "data_read_per_join": "32K"
            },
            "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
79185 88,3605,11891,76M
79358 78,3605,3606,76M
79359 106,3606,2185M
80067 3605,3607,87M
82647 78,3605,5740,191M
82650 108,3605,11891,78M
82658 106,3606,78M
82659 108,3605,11891,78M
82662 73,108M
82663 106,3605,78M
82664 106,3605,3606,78M
82665 78,3803,3804,2566M
82670 118,3803,3804,78M
82674 238,11903,183M
82675 238,11903,183M
82677 238,11903,183M
83702 3605,3784,106M
153234 78,3803,3804,2566M
169289 78,3605,3606,76M
187599 88,3605,11891,76M
187601 88,3605,11891,76M
188170 253,3605,3784,78M
188620 191,3605,3784,78M
189127 253,3607,3784,87M
191122 253,3784,252M
191601 229,3605,3784,78M
191770 3784,5740,6634,228M
197476 226,3784,13519,74M
199702 226,3784,13519,74M
201635 227,3784,13519,74M
203577 209,3784,3802,124M
204373 236,3784,22165,112M
210711 260,3605,3784,108M
247890 147,2M
247892 147,2M
247897 147,2M
247902 147,2M
258388 105,3803,3804,78M
259182 183,3605,3804,78M
259310 183,3605,3804,78M
259598 183,3605,3804,78M
259643 183,3803,3804,78M
259655 118,3605,3804,78M
269090 236,3758,11903,14265,14266,242M
269091 48,3758,11903,191M
269093 236,3758,11903,242M
269094 236,3758,11903,242M
269095 48,3758,11903,242M
269096 242,3758,11903,236M
269097 236,3758,11903,242M
269098 242,3758,11903,236M
269100 236,3758,11903,242M
269106 236,242M
269107 48,3758,11903,242M
269108 236,3758,11903,242M
269110 48,3758,11903,242M
269111 236,3758,11903,242M
269113 239,3758,11903,242M
269116 236,3758,11903,242M
269118 242,11903,19820,236M
283319 3784,6634,20983,179M
283328 260,3784,20983,6634M
284130 3784,6634,20983,260M
292893 213,3607,3784,100M
306484 50,3784,22165,48M
306494 48,3784,22165,45M