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 (
    10134, 10232, 10238, 10321, 10322, 10323, 
    10324, 10372, 10388, 10457, 10459, 
    10555, 10970, 10972, 11176, 11222, 
    11320, 8381, 10007, 7526, 7538, 7551, 
    7552, 7574, 7583, 7585, 7632, 7634, 
    7635, 7641, 7643, 7727, 7730, 7746, 
    7752, 7765, 7773, 7777, 8855, 8865
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00185

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "63.96"
    },
    "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": 66,
            "rows_produced_per_join": 66,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (10134,10232,10238,10321,10322,10323,10324,10372,10388,10457,10459,10555,10970,10972,11176,11222,11320,8381,10007,7526,7538,7551,7552,7574,7583,7585,7632,7634,7635,7641,7643,7727,7730,7746,7752,7765,7773,7777,8855,8865))",
            "cost_info": {
              "read_cost": "33.11",
              "eval_cost": "6.60",
              "prefix_cost": "39.71",
              "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": 3,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "16.50",
              "eval_cost": "0.33",
              "prefix_cost": "62.81",
              "data_read_per_join": "10K"
            },
            "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": 3,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.83",
              "eval_cost": "0.33",
              "prefix_cost": "63.97",
              "data_read_per_join": "52"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
7526 466M
7538 372M 0
7551 575M
7552 575M
7574 466M
7583 587M
7585 587M
7632 460M
7634 460M
7635 460M
7641 460M
7643 556M
7727 574M
7730 574M
7746 574M
7752 573M
7765 556M
7773 556M
7777 575M
8381 573M
8855 574M
8865 574M
10007 573M
10134 372,454,453,190,174,166M 0
10232 459M
10238 459M
10321 372,454,453,190,174,166M 0
10322 372,454,453,190,174,166M 0
10323 372,454,453,190,174,166M 0
10324 583M
10372 556M
10388 372,587M 0
10457 597,566M
10459 566,597M
10555 655M
10970 467M
10972 467M
11176 595M
11222 556,554M
11320 597M