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.company_id = 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 (
    427, 408, 382, 418, 1931, 381, 1529, 1465, 
    1933, 1935, 329, 439, 393, 394, 396, 
    383, 440, 327, 1934, 385, 405, 413, 1937, 
    414
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00787

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "180.54"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "19.14"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 115,
            "rows_produced_per_join": 2,
            "filtered": "2.00",
            "cost_info": {
              "read_cost": "27.56",
              "eval_cost": "0.46",
              "prefix_cost": "28.02",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "company_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`eshopuga_upgr_4122`.`cscart_categories`.`company_id` = 1) and ((`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids`)) and (`eshopuga_upgr_4122`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "eshopuga_upgr_4122.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 19,
            "filtered": "20.81",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (427,408,382,418,1931,381,1529,1465,1933,1935,329,439,393,394,396,383,440,327,1934,385,405,413,1937,414))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "3.83",
              "prefix_cost": "138.42",
              "data_read_per_join": "306"
            },
            "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",
              "eshopuga_upgr_4122.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 19,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "19.14",
              "eval_cost": "3.83",
              "prefix_cost": "161.39",
              "data_read_per_join": "306"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
327 373,371,355,380,361,363,375,374,372,384,358,370,382,350,357,356,377,378,359,385,386,376,362,349M,369,379,353,381,383,352,351,360,354 0
329 338,352,351,354,373,339,371,355,375,374,372,358,370,350,357,356,377,378,376,342,349M,369,353 0
381 349,383,353,360,338,347,352,344,351,380,361,363,354,343,373,339,371,355,337M,375,384,382,374,372,340,359,358,370,385,350,357,386,356,378,362,376,342,345,341,379,381 0
382 376,342,345,341,369,379,381,349,383,353,338,347,352,344,351,354,343,373,339,371,355,337M,375,384,382,377,374,372,340,358,370,385,350,357,386,356,378 0
383 356,378,376,342,368,345,341,360,381,349,353,361,363,338,347,352,344,351,354,343,373,339,371,355,337M,375,384,359,377,374,372,362,340,358,370,385,350,357,386 0
385 393,377,374,372,392,362,340,358,370,394,350,357,356,378,369,376,342,368,345,341,360,349,391,395,388,353,361,363,338,347,352,344,351,354,343,373,339,371,355,337M,375,396,359,390 0
393 355,337M,375,385,386,377,374,372,379,340,358,370,350,357,356,383,378,369,380,381,376,342,345,341,349,353,338,382,347,352,344,351,354,384,343,373,339,371 0
394 352,344,351,354,384,343,373,339,371,355,337M,375,385,386,377,374,372,379,340,358,370,350,357,356,383,378,369,380,381,376,342,345,341,349,353,338,382,347 0
396 353,338,347,352,344,351,354,343,373,339,371,355,337M,375,377,374,372,340,358,370,350,357,356,378,369,376,342,345,341,349 0
405 345,341,396,359,390,349,393,353,392,362,338,394,347,352,344,351,354,343,373,339,371,355,368,337M,375,360,377,374,391,395,372,388,340,358,370,361,363,350,357,356,378,369,376,342 0
408 378,369,376,382,342,345,341,384,349,353,338,385,347,386,352,344,351,354,379,343,373,339,371,355,383,337M,375,380,381,377,374,372,340,358,370,350,357,356 0
413 372,340,358,370,350,357,356,378,369,359,376,342,345,341,362,349,353,338,352,344,351,368,354,343,373,339,360,371,355,337M,375,361,363,377,374 0
414 337M,375,361,363,377,374,372,340,358,370,350,357,356,378,369,359,376,342,345,341,362,349,353,338,352,344,351,368,354,343,373,339,360,371,355 0
418 354,343,373,339,371,355,337M,375,363,377,374,372,340,358,370,350,357,356,378,369,376,342,345,341,349,353,338,352,344,351 0
427 338,352,344,351,354,343,373,339,371,382,355,337M,375,384,377,374,372,340,358,370,350,357,356,385,347,386,378,369,379,376,342,345,341,383,380,349,381,353 0
439 349,360,381,353,338,361,352,344,351,354,343,373,363,339,371,382,355,337M,375,384,359,377,374,372,340,358,370,350,357,362,385,386,378,369,379,376,342,345,341,368,383 0
440 376,368,360,396,390,393,361,392,394,373,363,371,375,359M,377,374,372,370,391,395,388,362,369 0
1465 379,388,362,380,342,345,341,369,383,376,349,381,353,368,338,360,396,352,344,390,351,354,393,343,361M,339,392,382,394,355,337,373,363,371,384,356,347,375,340,358,350,357,359,385,377,374,386,378,372,370,391,395 0
1529 350,357,359,385,377,374,386,378,372,370,391,395,379,388,362,380,342,345,341,369,376,349M,381,353,368,338,360,396,352,344,390,351,354,393,343,361,339,392,394,355,337,373,363,371,384,356,347,375,340,358 0
1931 363,371,340,350,359,385,374,372,391,395,379,388,362,380,342,345,369,376,349,381,353,338,360,396,390,361M,339,337 0
1933 361M,339,337,363,386,340,370,350,359,374,341,372,391,379,388,362,345,369,376,349,381,352,338,360,396,390,394,355 0
1934 360,384,396,356,390,394,355,358,361M,339,377,337,363,340,370,395,350,359,342,374,372,391,379,362,345,344,369,354,349,381,352,338,373 0
1935 349,381,352,338,360,384,390,394,361M,339,337,363,380,340,395,350,388,359,342,374,372,391,379,393,362,376,345,344,369 0
1937 345,344,369,347,375,373,349,357,371,381,396,352,356,355,378,338,358,360,384,385,390,394,377,386,361M,339,341,337,370,368,363,380,382,353,351,340,395,350,388,343,359,342,374,392,372,391,354,379,393,362,376 0