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 = 361 
WHERE 
  cscart_products_categories.product_id IN (
    421, 443, 1971, 1959, 1930, 1960, 436, 
    438, 437, 1961, 1931, 381, 1529, 1465, 
    1962, 1933, 1935, 1958, 428, 406, 439, 
    390, 1969, 398, 1964, 434, 383, 1927, 
    435, 419, 403, 324, 1965, 440, 1966, 
    431, 1928, 1973, 1968, 1963
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01023

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "186.40"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "21.81"
      },
      "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": 21,
            "filtered": "23.70",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,443,1971,1959,1930,1960,436,438,437,1961,1931,381,1529,1465,1962,1933,1935,1958,428,406,439,390,1969,398,1964,434,383,1927,435,419,403,324,1965,440,1966,431,1928,1973,1968,1963))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.36",
              "prefix_cost": "138.42",
              "data_read_per_join": "348"
            },
            "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": 21,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "21.81",
              "eval_cost": "4.36",
              "prefix_cost": "164.59",
              "data_read_per_join": "348"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
324 359,388,356,361,351,368,360,354,357,392,393,340,362,352,358,391,390,394,396,355,363,353,395,338M,349,350 0
381 374,338,337M,349,371,350,370,344,359,341,343,356,361,351,376,384,339,360,354,357,340,362,352,342,383,385,358,372,373,347,355,380,382,363,345,378,386,379,381,353,375 0
383 386,381,353,375,374,338,337M,349,371,350,370,344,359,368,341,343,356,361,351,376,384,339,377,360,354,357,340,362,352,342,385,358,372,373,347,355,363,345,378 0
390 395,347,355,363,345,353,388,338,337M,349,350,392,344,359,368,393,341,343,356,361,351,391,339,390,394,396,360,354,357,340,362,352,342,358 0
398 362,352,342,358,395,389,347,355,363,345,353,388,338,337M,349,350,392,344,359,368,393,341,343,356,361,351,391,339,390,394,396,360,354,357,340 0
403 394,360,362,395,363,388,392,359M,368,393,361 0
406 390,396,354,361,357,340,394,352,342,360,358,362,347,355,345,395,353,363,338,337M,349,350,388,344,341,343,356,351,392,359,368,391,393,339 0
419 356,351,392,359,368,391,393,339,390,396,354,361,357,340,394,352,342,360,389,358,362,355,345,395,353,363,338,337M,349,350,388,344,341,343 0
421 350,388,344,341,343,356,351,392,359,368,391,393,339,390,396,354,361,357,340,394,352,342,360,358,362,355,345,395,353,363,338,337M,349 0
428 363,338,337M,349,350,388,344,341,343,356,351,392,359,368,391,393,339,390,396,354,361,347,357,340,394,352,342,360,358,362,355,345,395,353 0
431 355,345,395,353,363,338,337M,349,350,388,344,341,343,356,351,392,359,368,391,393,339,390,396,354,361,357,394,352,342,360,358,362 0
434 379,358,362,386,355,381,345,353,363,338,337M,349,350,344,341,343,384,356,351,347,383,359,368,339,340,354,361,357,385,380,382,352,342,360 0
435 361,385,380,382,352,360,379,362,395,386,381,388,363,349M,392,391,393,390,396,384,351,383,359,368,394 0
436 359M,368,361,360,362,363 0
437 359M,368,361,360,362,363 0
438 359M,368,361,360,362,363 0
439 351,357,373,383,342,363,378,358,375,385,382,352,374,355,379,345,371,353,370,386,381,359,368,369,338,337M,361,350,376,377,344,360,341,349,343,362,339,340,372,384,354 0
440 362,394,372,373,363,375,395,374,371,370,388,359M,368,369,361,376,377,392,360,391,393,390,396 0
443 360,362,363,359M,368,361 0
1465 377,368,392,391,393,339,340,390,396,361M,384,354,351,357,383,360,380,394,342,372,378,373,362,358,385,382,352,355,379,345,375,395,363,353,374,386,381,371,338,337,370,350,388,356,347,344,369,341,349,343,376,359 0
1529 347,344,369,341,349M,343,376,359,377,368,392,391,393,339,340,390,396,361,384,354,351,357,360,380,394,342,372,378,373,362,358,385,352,355,379,345,375,395,363,353,374,386,381,371,338,337,370,350,388,356 0
1927 338,337,370,350,369,349,359,377,391,339,340,390,361M,351,378,362,358,379,345,363,353,374 0
1928 374,338,370,350,369,349,359,391,339,390,361M,378,362,395,379,381,345 0
1930 395,363,353,379,381,388,345,356,341,337,376,338,350,354,377,369,340,349,359,351,391,339,390,361M,352,355,375,362 0
1931 371,362,395,363,353,374,379,381,388,345,337,396,376,360,338,380,350,342,372,369,385,340,349,359,391,339,390,361M 0
1933 391,339,390,361M,362,363,341,374,370,379,381,388,345,337,394,396,376,360,338,350,372,369,340,349,352,359,386,355 0
1935 369,340,349,352,359,391,339,390,361M,344,393,395,384,362,363,374,379,381,388,345,337,380,394,342,376,360,338,350,372 0
1958 338,369,340,349,352,359,368,339,361M,370,362,377,363,379,381,388,337,360 0
1959 337,350,360,338,369,340,349,352,359,368,339,361M,370,362,377,363,379,381 0
1960 363,379,381,337,360,338,369,340,349,352,359,368,339,361M,370,362,378,377 0
1961 370,378,362,377,363,350,379,381,337,360,338,369,340,349,359,368,339,361M 0
1962 370,362,377,363,390,350,379,381,337,360,338,352,369,340,349,359,388,339,361M 0
1963 359,388,339,361M,378,370,362,377,363,350,379,381,337,360,338,352,369,340,349 0
1964 369,340,349,359,339,361M,378,370,362,377,363,379,381,337,360,368,338 0
1965 360,368,338,369,340,349,359,339,361M,370,362,377,363,379,381,337,352 0
1966 379,381,337,352,360,368,338,369,340,349,359,339,361M,370,362,377,363 0
1968 362,363,379,381,337,352,360,338,369,340,349,359,350,339,361M,370 0
1969 370,362,363,379,381,368,337,352,360,338,369,340,349,359,350,339,361M 0
1971 377,339,361M,370,362,363,379,381,368,337,352,360,338,369,340,349,359,350 0
1973 369,340,349,359,377,339,361M,370,362,363,379,381,368,337,352,360,338 0