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, 
  product_position_source.position AS position 
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') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 664 
WHERE 
  cscart_products_categories.product_id IN (
    11458, 11143, 11231, 11152, 11238, 11439, 
    11453, 11202, 11360, 11198, 11272, 
    11274, 11300, 11500, 11522, 11168, 
    11233, 11287, 11217, 11218, 11226, 
    11271, 11364, 11164, 11232, 11288, 
    11526, 11024, 11080, 11204, 11220, 
    11200, 11270, 10991, 11003, 11211, 
    11216, 11240, 11084, 11210
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00290

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "101.57"
    },
    "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": 112,
            "rows_produced_per_join": 112,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (11458,11143,11231,11152,11238,11439,11453,11202,11360,11198,11272,11274,11300,11500,11522,11168,11233,11287,11217,11218,11226,11271,11364,11164,11232,11288,11526,11024,11080,11204,11220,11200,11270,10991,11003,11211,11216,11240,11084,11210))",
            "cost_info": {
              "read_cost": "49.21",
              "eval_cost": "11.20",
              "prefix_cost": "60.41",
              "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": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "28.00",
              "eval_cost": "0.56",
              "prefix_cost": "99.61",
              "data_read_per_join": "17K"
            },
            "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')))"
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.40",
              "eval_cost": "0.56",
              "prefix_cost": "101.57",
              "data_read_per_join": "89"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
10991 664M 0
11003 664M 0
11024 664M 0
11080 664M 0
11084 664M 0
11143 664M 0
11152 664M 0
11164 664M 0
11168 664M 0
11198 664M 0
11200 664M 0
11202 664M 0
11204 664M 0
11210 664M 0
11211 664M 0
11216 664M 0
11217 664M 0
11218 664M 0
11220 664M 0
11226 664M 0
11231 664M 0
11232 664M 0
11233 664M 0
11238 664M 0
11240 664M 0
11270 664M 0
11271 664M 0
11272 664M 0
11274 664M 0
11287 664M 0
11288 664M 0
11300 664M 0
11360 664M 0
11364 664M 0
11439 664M 0
11453 664M 0
11458 664M 0
11500 664M 0
11522 664M 0
11526 664M 0