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 (
    8102, 7086, 7195, 6991, 7169, 7120, 7167, 
    7555, 6992, 7568, 8409, 7029, 9293, 
    7170, 7174, 9217, 9511, 9292, 7222, 
    7223, 6988, 9512, 8099, 8370, 8411, 
    9194, 9189, 9192, 8408, 9149, 9158, 
    9191, 9366, 9501, 8998, 9021, 9218, 
    9291, 9294, 9363
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00155

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "42.81"
    },
    "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": 41,
            "rows_produced_per_join": 41,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (8102,7086,7195,6991,7169,7120,7167,7555,6992,7568,8409,7029,9293,7170,7174,9217,9511,9292,7222,7223,6988,9512,8099,8370,8411,9194,9189,9192,8408,9149,9158,9191,9366,9501,8998,9021,9218,9291,9294,9363))",
            "cost_info": {
              "read_cost": "24.36",
              "eval_cost": "4.10",
              "prefix_cost": "28.46",
              "data_read_per_join": "656"
            },
            "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": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 2,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "10.25",
              "eval_cost": "0.21",
              "prefix_cost": "42.81",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6988 640M
6991 641,630M
6992 641,630M
7029 637M
7086 630M
7120 630M
7167 630M
7169 630M
7170 630M
7174 630M
7195 623M
7222 640M
7223 640M
7555 633M
7568 633M
8099 641M
8102 642M
8370 642M
8408 473M
8409 642M
8411 631M
8998 640M
9021 640M
9149 641M
9158 641M
9189 641M
9191 641M
9192 641M
9194 642M
9217 642M
9218 642M
9291 631M
9292 642M
9293 642M
9294 642M
9363 642M
9366 642M
9501 644M
9511 646M
9512 646M