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 = 457 
WHERE 
  cscart_products_categories.product_id IN (
    2603, 3136, 2587, 2761, 2694, 3096, 2723, 
    2742, 3556, 2593, 3104, 2618, 2828, 
    2613, 2619, 2872, 2704, 3593, 4888, 
    3423, 5168, 2739, 3291, 2841, 5155, 
    3876, 2561, 3812, 5124, 2865, 2734, 
    3369, 3139, 5157, 2700, 5121, 5929, 
    2701, 2797, 6271, 5938, 4886, 4885, 
    8243, 5933, 8603, 10022, 8272, 7878, 
    8879, 7880, 8458
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00259

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "140.66"
    },
    "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": 111,
            "rows_produced_per_join": 111,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2603,3136,2587,2761,2694,3096,2723,2742,3556,2593,3104,2618,2828,2613,2619,2872,2704,3593,4888,3423,5168,2739,3291,2841,5155,3876,2561,3812,5124,2865,2734,3369,3139,5157,2700,5121,5929,2701,2797,6271,5938,4886,4885,8243,5933,8603,10022,8272,7878,8879,7880,8458))",
            "cost_info": {
              "read_cost": "51.86",
              "eval_cost": "11.10",
              "prefix_cost": "62.96",
              "data_read_per_join": "1K"
            },
            "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": 111,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "27.75",
              "eval_cost": "11.10",
              "prefix_cost": "101.81",
              "data_read_per_join": "1K"
            },
            "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": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "27.75",
              "eval_cost": "0.56",
              "prefix_cost": "140.66",
              "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')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
2561 329,166,457M 0
2587 329,166,457M 0
2593 329,166,457M 0
2603 329,166,457M 0
2613 329,166,457M 0
2618 329,166,457M 0
2619 329,166,457M 0
2694 329,166,457M 0
2700 329,166,457M 0
2701 329,166,457M 0
2704 329,166,457M 0
2723 329,166,457M 0
2734 329,166,457M 0
2739 329,166,457M 0
2742 329,166,457M 0
2761 329,166,457M 0
2797 329,166,457M 0
2828 329,166,457M 0
2841 329,166,457M 0
2865 329,166,457M 0
2872 329,166,457M 0
3096 329,166,457M 0
3104 329,166,457M 0
3136 329,166,457M 0
3139 329,166,457M 0
3291 329,166,457M 0
3369 329,166,457M 0
3423 329,166,457M 0
3556 329,166,457M 0
3593 329,166,457M 0
3812 329,166,457M 0
3876 329,166,457M 0
4885 329,166,457M 0
4886 166,329,457M 0
4888 329,166,457M 0
5121 329,166,457M 0
5124 329,166,457M 0
5155 329,166,457M 0
5157 329,166,457M 0
5168 329,166,457M 0
5929 329,166,457M 0
5933 329,166,457M 0
5938 329,166,457M 0
6271 457M 0
7878 457M 0
7880 457M 0
8243 457,344M 0
8272 457M 0
8458 457M 0
8603 457M 0
8879 457M 0
10022 457M 0