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, 128, 51118, 51117, 51116, 
    51115, 51114, 51113, 51123, 51122, 
    51121, 92, 49, 51129, 51128, 51127, 
    51126, 51125, 48, 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, 51155, 
    51154, 51153, 51152, 21, 51158, 51157, 
    51156, 53, 51160, 51159, 134
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00278

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "166.30"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "28.17"
      },
      "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": 28,
            "filtered": "10.22",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (130,51106,51107,51112,51111,51110,51109,51108,128,51118,51117,51116,51115,51114,51113,51123,51122,51121,92,49,51129,51128,51127,51126,51125,48,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,51155,51154,51153,51152,21,51158,51157,51156,53,51160,51159,134))",
            "cost_info": {
              "read_cost": "68.94",
              "eval_cost": "2.82",
              "prefix_cost": "138.14",
              "data_read_per_join": "450"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
21 43,10,40M
37 42,10,40M
38 10,42,40M
39 10,42,40M
40 10,44,40M
41 10,43,40M
48 10,44,40M
49 10,43,40M
53 10,44,40M
92 42,10,40M
128 43,10,40M
130 42,10,40M
134 10,45M
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
51113 10,43,40M
51114 10,43,40M
51115 10,43,40M
51116 10,43,40M
51117 10,43,40M
51118 10,43,40M
51121 10,42,40M
51122 10,42,40M
51123 10,42,40M
51125 10,44,40M
51126 44,10,40M
51127 44,10,40M
51128 44,10,40M
51129 44,10,40M
51130 43,10,40M
51131 43,10,40M
51132 43,10,40M
51133 43,10,40M
51134 43,10,40M
51135 44,10,40M
51136 44,10,40M
51137 44,10,40M
51138 44,10,40M
51139 44,10,40M
51140 42,10,40M
51141 42,10,40M
51142 42,10,40M
51143 10,42,40M
51144 42,10,40M
51145 42,10,40M
51146 42,10,40M
51147 42,10,40M
51148 42,10,40M
51149 10,42,40M
51150 10,42,40M
51152 10,43,40M
51153 10,43,40M
51154 10,43,40M
51155 10,43,40M
51156 44,10,40M
51157 44,10,40M
51158 44,10,40M
51159 44,10,40M
51160 44,10,40M