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 (
    4941, 4940, 4939, 4935, 5815, 5816, 5948, 
    6128, 6127, 6126, 6129, 6130, 6131, 
    6132, 6133, 6134, 6135, 5952, 6138, 
    6137, 6136, 6139, 6140, 6141, 6142, 
    6143, 6031, 6032, 6033, 6034, 6035, 
    6048, 6049, 6050, 6051, 6052, 6053, 
    6054, 6055, 6056, 6057, 6058, 6059, 
    5956, 6087, 6088, 6089, 6090, 6091, 
    6092, 6093, 6101, 6102, 6103, 6104, 
    6105, 6106, 6107, 6108, 6109, 6164, 
    6165, 6166, 6167, 6168, 6169, 6170, 
    6171, 6172, 6173, 6174, 6175, 6176, 
    6177, 5804, 6193, 6196, 6195, 6194, 
    6197, 6198, 6199, 6200, 6201, 6202, 
    10089
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00379

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "196.71"
    },
    "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": 219,
            "rows_produced_per_join": 219,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (4941,4940,4939,4935,5815,5816,5948,6128,6127,6126,6129,6130,6131,6132,6133,6134,6135,5952,6138,6137,6136,6139,6140,6141,6142,6143,6031,6032,6033,6034,6035,6048,6049,6050,6051,6052,6053,6054,6055,6056,6057,6058,6059,5956,6087,6088,6089,6090,6091,6092,6093,6101,6102,6103,6104,6105,6106,6107,6108,6109,6164,6165,6166,6167,6168,6169,6170,6171,6172,6173,6174,6175,6176,6177,5804,6193,6196,6195,6194,6197,6198,6199,6200,6201,6202,10089))",
            "cost_info": {
              "read_cost": "98.16",
              "eval_cost": "21.90",
              "prefix_cost": "120.06",
              "data_read_per_join": "3K"
            },
            "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": 10,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "54.75",
              "eval_cost": "1.10",
              "prefix_cost": "196.71",
              "data_read_per_join": "34K"
            },
            "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
4935 166,423,449M
4939 166,423,449M
4940 166,423,449M
4941 166,423,449M
5804 423,424,450,166M
5815 308,250,383,350,166,387M
5816 308,250,350,383,166,387M
5948 423,166,585M
5952 423,166,585M
5956 166,423,449M
6031 423,166,585M
6032 423,166,585M
6033 166,423,585M
6034 166,423,585M
6035 423,166,585M
6048 423,166,585M
6049 166,423,585M
6050 166,423,585M
6051 423,166,585M
6052 423,166,585M
6053 423,166,585M
6054 423,166,585M
6055 166,423,585M
6056 423,166,585M
6057 423,166,585M
6058 423,166,585M
6059 423,166,585M
6087 166,423,449M
6088 166,423,449M
6089 166,423,449M
6090 166,423,449M
6091 423,166,449M
6092 166,423,449M
6093 423,166,449M
6101 166,423,586M
6102 166,423,586M
6103 166,423,586M
6104 166,423,586M
6105 166,423,586M
6106 166,423,586M
6107 166,423,586M
6108 166,423,586M
6109 166,423,586M
6126 423,166,585M
6127 423,166,585M
6128 423,166,585M
6129 423,166,585M
6130 423,166,585M
6131 423,166,585M
6132 423,166,585M
6133 423,166,585M
6134 423,166,585M
6135 423,166,585M
6136 423,166,585M
6137 423,166,585M
6138 423,166,585M
6139 423,166,585M
6140 423,166,585M
6141 423,166,585M
6142 423,166,585M
6143 423,166,585M
6164 423,166,585M
6165 423,166,585M
6166 423,166,585M
6167 423,166,585M
6168 423,166,585M
6169 423,166,585M
6170 423,166,585M
6171 423,166,585M
6172 423,166,585M
6173 423,166,585M
6174 423,166,585M
6175 423,166,585M
6176 423,166,585M
6177 423,166,585M
6193 423,450,424,166M
6194 423,166,449M
6195 423,166,449M
6196 166,423,449M
6197 166,423,449M
6198 166,423,449M
6199 423,166,449M
6200 423,166,449M
6201 423,166,449M
6202 423,166,449M
10089 167M