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 = 250 
WHERE 
  cscart_products_categories.product_id IN (
    5022, 5006, 3927, 4781, 3335, 4961, 5009, 
    3336, 5208, 3954, 3509, 3934, 3961, 
    4006, 5467, 5554, 3958, 5013, 3933, 
    5370, 8789, 3484, 5566, 4824, 4989, 
    5377, 3477, 4821, 5369, 4660, 5188, 
    5567, 4238, 3468, 4005, 4010, 5477, 
    4292, 5866, 5374
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00459

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "166.15"
    },
    "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": 191,
            "rows_produced_per_join": 191,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (5022,5006,3927,4781,3335,4961,5009,3336,5208,3954,3509,3934,3961,4006,5467,5554,3958,5013,3933,5370,8789,3484,5566,4824,4989,5377,3477,4821,5369,4660,5188,5567,4238,3468,4005,4010,5477,4292,5866,5374))",
            "cost_info": {
              "read_cost": "76.86",
              "eval_cost": "19.10",
              "prefix_cost": "95.96",
              "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": 9,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "47.75",
              "eval_cost": "0.96",
              "prefix_cost": "162.81",
              "data_read_per_join": "29K"
            },
            "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": 9,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "2.39",
              "eval_cost": "0.96",
              "prefix_cost": "166.15",
              "data_read_per_join": "152"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
3335 328,402,166,250,481,482M 0
3336 402,328,250,166,481,482M 0
3468 250,371,393M 0
3477 250,371,393M 0
3484 250,371,393M 0
3509 250,371,489M 0
3927 411,405,402,250,342,328,166,363M 0
3933 341,328,402,250,166,404M 0
3934 341,328,402,250,166,404M 0
3954 341,328,402,250,166,404M 0
3958 341,328,402,250,166,404M 0
3961 341,328,402,250,166,404M 0
4005 341,328,402,250,166,404M 0
4006 341,328,402,250,166,404M 0
4010 371,250,394M 0
4238 386,308,250,350,166,382M 0
4292 250,399,329,166,400M 0
4660 386,308,250,350,166,382M 0
4781 166,402,250,328,564,565M 0
4821 166,402,250,328,565,564M 0
4824 166,402,250,328,565,564M 0
4961 556,552,372,553,250,554M 0
4989 552,553,554,372,250,556M 0
5006 561,555,557,552,553,372,250,563M 0
5009 561,555,557,552,553,372,250,563M 0
5013 561,555,557,552,553,372,250,563M 0
5022 561,555,557,552,553,372,250,563M 0
5188 557,250,372,562,553,552,555,560M 0
5208 372,557,555,553,552,250,563,561M 0
5369 554,553,250,372,552,556M 0
5370 250,556,552,553,372,554M 0
5374 250,372,553,554,552,556M 0
5377 250,372,553,554,552,556M 0
5467 372,250,556,553,552,554M 0
5477 554,553,250,552,372,556M 0
5554 250,372,552,557,562,553,555,560M 0
5566 554,553,250,552,372,556M 0
5567 554,553,250,552,372,556M 0
5866 423,308,387,250,350,166,383M 0
8789 250,336M 0