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 = 383 
WHERE 
  cscart_products_categories.product_id IN (
    5625, 3751, 4231, 5932, 4431, 4460, 5613, 
    3752, 4293, 4205, 5927, 4470, 5815, 
    4258, 5866, 4271, 6162, 4471, 5857, 
    4291, 5862, 6113, 5808, 5616, 4459, 
    6116, 8799, 10080, 10083
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00216

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "163.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": 136,
            "rows_produced_per_join": 136,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (5625,3751,4231,5932,4431,4460,5613,3752,4293,4205,5927,4470,5815,4258,5866,4271,6162,4471,5857,4291,5862,6113,5808,5616,4459,6116,8799,10080,10083))",
            "cost_info": {
              "read_cost": "54.86",
              "eval_cost": "13.60",
              "prefix_cost": "68.46",
              "data_read_per_join": "2K"
            },
            "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": 136,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "34.00",
              "eval_cost": "13.60",
              "prefix_cost": "116.06",
              "data_read_per_join": "2K"
            },
            "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": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "34.00",
              "eval_cost": "0.68",
              "prefix_cost": "163.66",
              "data_read_per_join": "21K"
            },
            "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
3751 350,166,308,250,387,383M 0
3752 350,166,387,250,308,383M 0
4205 387,308,250,350,166,383M 0
4231 387,308,250,350,166,383M 0
4258 387,308,250,350,166,383M 0
4271 387,308,250,350,166,383M 0
4291 383,308,250,350,166,387M 0
4293 387,308,250,350,166,383M 0
4431 387,308,250,350,166,383M 0
4459 387,308,250,350,166,383M 0
4460 387,308,250,350,166,383M 0
4470 387,308,250,350,166,383M 0
4471 387,308,250,350,166,383M 0
5613 387,308,250,350,166,383M 0
5616 308,387,250,350,166,383M 0
5625 308,387,250,350,166,383M 0
5808 308,387,250,350,166,383M 0
5815 308,250,383,350,166,387M 0
5857 308,250,350,166,387,383M 0
5862 423,308,387,250,350,166,383M 0
5866 423,308,387,250,350,166,383M 0
5927 308,250,350,423,166,387,383M 0
5932 423,308,387,250,350,166,383M 0
6113 350,166,308,387,250,383M 0
6116 350,166,308,387,250,383M 0
6162 350,166,387,308,250,383M 0
8799 387,350,308,383M 0
10080 383,387M 0
10083 383,387M 0