SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    130, 51106, 51107, 51112, 51111, 51110, 
    51109, 51108, 51182, 51180, 51179, 
    51178, 51177, 93, 10, 51232, 12, 51238, 
    51237, 51236, 51235, 51234, 51233, 
    51246, 51245, 51244, 35, 51248, 51247, 
    51256, 51255, 51254, 33, 32, 51281, 
    51280, 51279, 51278, 51282, 7, 16, 54, 
    51313, 51312, 51314, 51311, 51310, 
    89, 51390, 51391, 51392, 51393, 51394
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00184

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "146.06"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 166,
            "rows_produced_per_join": 166,
            "filtered": "100.00",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (130,51106,51107,51112,51111,51110,51109,51108,51182,51180,51179,51178,51177,93,10,51232,12,51238,51237,51236,51235,51234,51233,51246,51245,51244,35,51248,51247,51256,51255,51254,33,32,51281,51280,51279,51278,51282,7,16,54,51313,51312,51314,51311,51310,89,51390,51391,51392,51393,51394))",
            "cost_info": {
              "read_cost": "71.36",
              "eval_cost": "16.60",
              "prefix_cost": "87.96",
              "data_read_per_join": "2K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test_uchur_k.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 8,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "41.50",
              "eval_cost": "0.83",
              "prefix_cost": "146.06",
              "data_read_per_join": "43K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test_uchur_k`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test_uchur_k`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test_uchur_k`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test_uchur_k`.`cscart_categories`.`usergroup_ids`))) and (`test_uchur_k`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
7 42,7,40M
10 6,42,40M
12 42,7,390,40M
16 6,44,40M
32 42,7,40M
33 42,7,40M
35 44,7,40M
54 44,24,40M
89 25,42,40M
93 42,9,40M
130 42,10,40M
51106 10,42,40M
51107 10,42,40M
51108 10,42,40M
51109 10,42,40M
51110 10,42,40M
51111 10,42,40M
51112 10,42,40M
51177 9,42,40M
51178 9,42,40M
51179 9,42,40M
51180 9,42,40M
51182 9,42,40M
51232 7,42,390,40M
51233 390,7,42,40M
51234 390,7,42,40M
51235 7,42,390,40M
51236 7,42,390,40M
51237 7,42,390,40M
51238 42,390,7,40M
51244 7,44,40M
51245 7,44,40M
51246 7,44,40M
51247 7,44,40M
51248 7,44,40M
51254 7,42,40M
51255 7,42,40M
51256 7,42,40M
51278 7,42,40M
51279 7,42,40M
51280 7,42,40M
51281 7,42,40M
51282 7,42,40M
51310 24,44,40M
51311 24,44,40M
51312 24,44,40M
51313 24,44,40M
51314 24,44,40M
51390 42,25,40M
51391 42,25,40M
51392 42,25,40M
51393 42,25,40M
51394 25,42,40M