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 (
    3011, 3012, 3013, 3014, 3015, 3016, 3017, 
    3018, 3019, 3021, 3022, 3023, 3024, 
    3026, 3030, 3029, 3031, 3036, 3034, 
    3033, 3037, 3038, 3039, 3040, 3041, 
    3055, 3058, 3059, 3066, 3067, 3069, 
    3070, 3071, 3072, 3602, 3078, 3079, 
    3080, 3084, 3085
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00201

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "88.41"
    },
    "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": 98,
            "rows_produced_per_join": 98,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (3011,3012,3013,3014,3015,3016,3017,3018,3019,3021,3022,3023,3024,3026,3030,3029,3031,3036,3034,3033,3037,3038,3039,3040,3041,3055,3058,3059,3066,3067,3069,3070,3071,3072,3602,3078,3079,3080,3084,3085))",
            "cost_info": {
              "read_cost": "44.31",
              "eval_cost": "9.80",
              "prefix_cost": "54.11",
              "data_read_per_join": "1K"
            },
            "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": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "24.50",
              "eval_cost": "0.49",
              "prefix_cost": "88.41",
              "data_read_per_join": "15K"
            },
            "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
3011 329,166,344M
3012 329,166,344M
3013 329,166,344M
3014 329,166,344M
3015 166,329,344M
3016 329,166
3017 166,329
3018 166,329
3019 166,329
3021 329,166,344M
3022 166,329,344M
3023 329,166,344M
3024 166,329,344M
3026 329,166,344M
3029 166,329,344M
3030 329,166,344M
3031 320,166,469M
3033 320,166,469M
3034 320,166,469M
3036 320,166,469M
3037 166,320,469M
3038 166,320,469M
3039 166,320,469M
3040 166,320,469M
3041 166,320,469M
3055 166,234,470M
3058 166,234,470M
3059 166,234,470M
3066 322,166,471M
3067 322,166,471M
3069 166,322,471M
3070 322,166,471M
3071 322,166,471M
3072 322,166,471M
3078 166,322,471M
3079 166,322,471M
3080 322,166,471M
3084 166,322,471M
3085 166,322,471M
3602 322,166,471M