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 (
    2805, 2808, 3114, 3115, 3150, 3151, 3213, 
    3214, 3216, 3215, 3552, 3553, 4915, 
    4917, 4924, 4923, 4922, 4921, 4920, 
    4919, 4918, 4925, 4927, 4926, 4944, 
    4942, 4945, 4959, 4958, 4973, 4972, 
    4971, 4970, 4969, 4968, 4967, 4966, 
    4965, 4964, 4963, 4962, 4987, 4986, 
    4985, 4984, 4977, 4976, 4981, 4980, 
    4979, 4978, 4982, 4983, 5687, 5688, 
    5689, 5690, 5691, 5692, 5693, 5694, 
    6026, 6025, 6027, 6028, 6029, 6030
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00303

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "156.76"
    },
    "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": 175,
            "rows_produced_per_join": 175,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2805,2808,3114,3115,3150,3151,3213,3214,3216,3215,3552,3553,4915,4917,4924,4923,4922,4921,4920,4919,4918,4925,4927,4926,4944,4942,4945,4959,4958,4973,4972,4971,4970,4969,4968,4967,4966,4965,4964,4963,4962,4987,4986,4985,4984,4977,4976,4981,4980,4979,4978,4982,4983,5687,5688,5689,5690,5691,5692,5693,5694,6026,6025,6027,6028,6029,6030))",
            "cost_info": {
              "read_cost": "78.01",
              "eval_cost": "17.50",
              "prefix_cost": "95.51",
              "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": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 8,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "43.75",
              "eval_cost": "0.88",
              "prefix_cost": "156.76",
              "data_read_per_join": "27K"
            },
            "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
2805 424,423,492,166M
2808 423,424,492,166M
3114 492,452,424,423,166M
3115 423,424,452,492,166M
3150 423,424,450,166M
3151 423,424,450,166M
3213 450,423,424,166M
3214 450,424,423,166M
3215 450,424,423,166M
3216 450,423,424,166M
3552 423,424,450,166M
3553 423,424,450,166M
4915 166,423,449M
4917 166,423,449M
4918 166,423,449M
4919 166,423,449M
4920 166,423,449M
4921 166,423,449M
4922 166,423,449M
4923 166,423,449M
4924 166,423,449M
4925 166,423,449M
4926 166,423,449M
4927 166,423,449M
4942 423,520,166M
4944 423,520,166M
4945 423,520,166M
4958 423,166,520M
4959 423,166,520M
4962 166,423,449M
4963 166,423,449M
4964 166,423,449M
4965 166,423,449M
4966 166,423,449M
4967 166,423,449M
4968 166,423,449M
4969 166,423,449M
4970 166,423,449M
4971 166,423,449M
4972 166,423,449M
4973 166,423,449M
4976 166,423,449M
4977 166,423,449M
4978 166,423,449M
4979 166,423,449M
4980 166,423,449M
4981 166,423,449M
4982 166,423,449M
4983 166,423,449M
4984 166,423,449M
4985 166,423,449M
4986 166,423,449M
4987 166,423,449M
5687 423,449,166M
5688 423,449,166M
5689 423,449,166M
5690 423,449,166M
5691 423,449,166M
5692 423,449,166M
5693 423,449,166M
5694 423,449,166M
6025 423,166,585M
6026 166,423,585M
6027 166,423,585M
6028 166,423,585M
6029 166,423,585M
6030 166,423,585M