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 = 372 
WHERE 
  cscart_products_categories.product_id IN (
    8501, 4974, 5277, 2459, 5640, 5284, 5376, 
    5287, 5281, 5397, 4995, 5270, 2901, 
    5278, 5187, 5549, 5235, 1528, 2776, 
    2432
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00254

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "89.21"
    },
    "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": 103,
            "rows_produced_per_join": 103,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (8501,4974,5277,2459,5640,5284,5376,5287,5281,5397,4995,5270,2901,5278,5187,5549,5235,1528,2776,2432))",
            "cost_info": {
              "read_cost": "41.06",
              "eval_cost": "10.30",
              "prefix_cost": "51.36",
              "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": "25.75",
              "eval_cost": "0.52",
              "prefix_cost": "87.41",
              "data_read_per_join": "16K"
            },
            "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.29",
              "eval_cost": "0.52",
              "prefix_cost": "89.21",
              "data_read_per_join": "82"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1528 453,454,372,174,166,190M 0
2432 372,174,166,453,454,190M 0
2459 372,166,453,454,174,190M 0
2776 372,461,462M 0
2901 372,384,460M 0
4974 372,552,556,553,250,554M 0
4995 552,553,554,372,250,556M 0
5187 557,555,250,372,562,553,552,560M 0
5235 372,551M 0
5270 250,372,563,557,555,553,552,561M 0
5277 250,372,563,557,555,553,552,561M 0
5278 250,372,563,557,555,553,552,561M 0
5281 250,372,563,557,555,553,552,561M 0
5284 400,372,563,557,555,553,552,561M 0
5287 372,250,563,557,555,553,552,561M 0
5376 372,250,553,552,554,556M 0
5397 372,250,553,554,552,556M 0
5549 553,250,552,554,372,556M 0
5640 555,553,250,560,557,552,372,562M 0
8501 372,453,166,174,454,190M 0