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 (
    82, 51076, 51073, 51072, 51074, 51075, 
    22711, 22710, 51077, 51080, 51078, 
    51079, 51132, 51131, 51134, 51133, 
    51130, 41, 51139, 51138, 51137, 51136, 
    51135, 40, 51144, 51143, 51142, 51141, 
    51140, 39, 51146, 51145, 38, 51148, 
    51147, 51150, 51149, 37, 51169, 51168, 
    51167, 51166, 90, 51171, 51170, 51205, 
    51204, 51203, 51202, 125, 51209, 51208, 
    51207, 51206, 124, 27, 22, 17, 18, 56, 
    51295, 117, 116, 115, 81, 11, 51326, 
    135, 106, 58, 57, 5, 51349, 122, 51357, 
    51360, 51359, 51358, 51361, 30, 51362, 
    51363, 51364, 51365, 65, 140, 51385, 
    51386, 51387, 51388, 51389
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00370

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "182.91"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "44.77"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 383,
            "rows_produced_per_join": 15,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "40.09",
              "eval_cost": "1.53",
              "prefix_cost": "41.62",
              "data_read_per_join": "81K"
            },
            "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')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "test_uchur_k.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 18,
            "rows_produced_per_join": 44,
            "filtered": "16.24",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (82,51076,51073,51072,51074,51075,22711,22710,51077,51080,51078,51079,51132,51131,51134,51133,51130,41,51139,51138,51137,51136,51135,40,51144,51143,51142,51141,51140,39,51146,51145,38,51148,51147,51150,51149,37,51169,51168,51167,51166,90,51171,51170,51205,51204,51203,51202,125,51209,51208,51207,51206,124,27,22,17,18,56,51295,117,116,115,81,11,51326,135,106,58,57,5,51349,122,51357,51360,51359,51358,51361,30,51362,51363,51364,51365,65,140,51385,51386,51387,51388,51389))",
            "cost_info": {
              "read_cost": "68.94",
              "eval_cost": "4.48",
              "prefix_cost": "138.14",
              "data_read_per_join": "716"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
5 6,40M,42
11 8,40M,42,394
17 6,40M,44
18 6,40M,43
22 6,40M,42
27 6,40M,42
30 18,40M,44,391
37 10,40M,42
38 10,40M,42
39 10,40M,42
40 10,40M,44
41 10,40M,43
56 8,40M,42,394
57 6,40M,44
58 6,40M,43
65 25M,45
81 8,40M,43,394
82 8,40M,44,394
90 9,40M,43
106 6,40M,43,394
115 8,40M,42,394
116 8,40M,42,394
117 8,40M,42,394
122 6,40M,42
124 7,40M,42
125 7,40M,42
135 36M,45,394
140 25,40M,42
22710 18M,40,42,392
22711 18M,40,42,392
51072 18M,40,42,392
51073 18M,40,42,392
51074 18M,40,42,392
51075 18M,40,42,392
51076 18M,40,42,392
51077 18M,40,42,392
51078 18M,40,42,392
51079 18M,40,42,392
51080 18M,40,42,392
51130 10,40M,43
51131 10,40M,43
51132 10,40M,43
51133 10,40M,43
51134 10,40M,43
51135 10,40M,44
51136 10,40M,44
51137 10,40M,44
51138 10,40M,44
51139 10,40M,44
51140 10,40M,42
51141 10,40M,42
51142 10,40M,42
51143 10,40M,42
51144 10,40M,42
51145 10,40M,42
51146 10,40M,42
51147 10,40M,42
51148 10,40M,42
51149 10,40M,42
51150 10,40M,42
51166 9,40M,43
51167 9,40M,43
51168 9,40M,43
51169 9,40M,43
51170 9,40M,43
51171 9,40M,43
51202 7,40M,42
51203 7,40M,42
51204 7,40M,42
51205 7,40M,42
51206 7,40M,42
51207 7,40M,42
51208 7,40M,42
51209 7,40M,42
51295 8,40M,42,394
51326 36M,45,394
51349 6,40M,42
51357 18,40M,42,391
51358 18,40M,42,391
51359 18,40M,42,391
51360 18,40M,42,391
51361 18,40M,44,391
51362 18,40M,44,391
51363 18,40M,44,391
51364 18,40M,44,391
51365 18,40M,44,391
51385 25,40M,42
51386 25,40M,42
51387 25,40M,42
51388 25,40M,42
51389 25,40M,42