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 = 450 
WHERE 
  cscart_products_categories.product_id IN (
    2698, 2340, 3834, 3306, 5848, 2352, 2431, 
    5114, 2922, 5798, 5801, 5829, 3301, 
    5852, 5928, 5847, 2341, 5794, 2702, 
    3147, 3520, 3529, 3146, 3809, 3148, 
    3215, 3213, 3552, 3149, 3157, 5791, 
    3845, 3150, 2228, 3664, 2230, 2655, 
    5890, 2226, 3843, 3840, 5891, 2719, 
    5111, 3385, 3831, 3289, 3382, 3222, 
    3522, 5804, 5113, 3537, 3387, 3388, 
    3528, 3819, 3309, 2918, 3384, 3532, 
    2720, 3807, 2727, 2229, 3550, 3220, 
    5107, 6112, 2429, 3805, 3524, 2921, 
    3668, 3702, 3670, 3684, 3682, 3230, 
    3303
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00410

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "322.46"
    },
    "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": 263,
            "rows_produced_per_join": 263,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2698,2340,3834,3306,5848,2352,2431,5114,2922,5798,5801,5829,3301,5852,5928,5847,2341,5794,2702,3147,3520,3529,3146,3809,3148,3215,3213,3552,3149,3157,5791,3845,3150,2228,3664,2230,2655,5890,2226,3843,3840,5891,2719,5111,3385,3831,3289,3382,3222,3522,5804,5113,3537,3387,3388,3528,3819,3309,2918,3384,3532,2720,3807,2727,2229,3550,3220,5107,6112,2429,3805,3524,2921,3668,3702,3670,3684,3682,3230,3303))",
            "cost_info": {
              "read_cost": "112.06",
              "eval_cost": "26.30",
              "prefix_cost": "138.36",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "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": 263,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "65.75",
              "eval_cost": "26.30",
              "prefix_cost": "230.41",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "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": 13,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "65.75",
              "eval_cost": "1.32",
              "prefix_cost": "322.46",
              "data_read_per_join": "41K"
            },
            "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 position
2226 424,423,450,166M 0
2228 166,424,450,423M 0
2229 424,423,450,166M 0
2230 424,423,450,166M 0
2340 424,423,450,166M 0
2341 424,423,450,166M 0
2352 424,423,450,166M 0
2429 450,424,423,166M 0
2431 423,424,450,166M 0
2655 423,424,450,166M 0
2698 450,424,423,166M 0
2702 423,424,450,166M 0
2719 423,424,450,166M 0
2720 423,424,450,166M 0
2727 423,424,450,166M 0
2918 423,424,450,166M 0
2921 423,424,450,166M 0
2922 423,424,450,166M 0
3146 423,424,450,166M 0
3147 423,424,450,166M 0
3148 423,424,450,166M 0
3149 423,424,450,166M 0
3150 423,424,450,166M 0
3157 423,424,450,166M 0
3213 450,423,424,166M 0
3215 450,424,423,166M 0
3220 450,424,423,166M 0
3222 450,424,423,166M 0
3230 450,424,423,166M 0
3289 450,424,423,166M 0
3301 423,424,450,166M 0
3303 450,424,423,166M 0
3306 450,424,423,166M 0
3309 423,450,424,166M 0
3382 423,424,450,166M 0
3384 423,424,450,166M 0
3385 423,424,450,166M 0
3387 423,424,450,166M 0
3388 423,424,450,166M 0
3520 423,424,450,166M 0
3522 423,424,450,166M 0
3524 423,424,450,166M 0
3528 423,424,450,166M 0
3529 423,424,450,166M 0
3532 423,424,450,166M 0
3537 423,450,424,166M 0
3550 423,450,424,166M 0
3552 423,424,450,166M 0
3664 423,424,450,166M 0
3668 166,424,423,450M 0
3670 424,166,423,450M 0
3682 424,166,423,450M 0
3684 424,166,423,450M 0
3702 166,423,424,450M 0
3805 423,424,450,166M 0
3807 423,424,450,166M 0
3809 423,424,450,166M 0
3819 424,423,450,166M 0
3831 423,424,450,166M 0
3834 423,424,450,166M 0
3840 423,424,450,166M 0
3843 423,424,450,166M 0
3845 423,424,450,166M 0
5107 450,424,423,166M 0
5111 450,423,424,166M 0
5113 450,424,423,166M 0
5114 450,423,424,166M 0
5791 450,424,423,166M 0
5794 450,424,423,166M 0
5798 423,450,424,166M 0
5801 423,424,450,166M 0
5804 423,424,450,166M 0
5829 423,424,450,166M 0
5847 423,424,450,166M 0
5848 423,424,450,166M 0
5852 423,424,450,166M 0
5890 423,424,450,166M 0
5891 423,424,450,166M 0
5928 423,424,450,166M 0
6112 424,423,166,450M 0