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 = 338 
WHERE 
  cscart_products_categories.product_id IN (
    383, 412, 1927, 419, 430, 324, 1965, 1966, 
    431, 432, 1928, 1973, 429, 1968, 384, 
    1963, 1934, 2000, 2001, 395, 420, 385, 
    405, 410, 413, 1970, 417, 1937, 414, 
    425, 407, 389, 402, 1972, 388, 426, 1974, 
    404, 1936, 387
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00886

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "187.57"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "22.34"
      },
      "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": 22,
            "filtered": "24.28",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (383,412,1927,419,430,324,1965,1966,431,432,1928,1973,429,1968,384,1963,1934,2000,2001,395,420,385,405,410,413,1970,417,1937,414,425,407,389,402,1972,388,426,1974,404,1936,387))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.47",
              "prefix_cost": "138.42",
              "data_read_per_join": "357"
            },
            "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": 22,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "22.34",
              "eval_cost": "4.47",
              "prefix_cost": "165.23",
              "data_read_per_join": "357"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
324 390,354,361,396,391,352,340,355,388,351,359,392,395,356,393,349,353,350,338M,368,362,360,357,394,363,358 0
383 353,350,338,368,384,362,360,357,347,363,337M,358,375,377,386,354,385,361,378,371,352,373,344,340,355,351,339,359,374,345,370,356,376,341,342,349,372,381,343 0
384 349,343,353,350,338,357,347,337M,358,354,352,344,340,355,351,339,345,356,341,342 0
385 341,394,342,372,368,390,362,349,360,363,375,343,353,350,338,396,357,377,391,347,337M,358,361,388,378,371,354,373,392,395,359,374,352,344,340,369,355,370,351,339,393,345,376,356 0
387 345,356,341,342,349,343,353,350,338,357,347,337M,358,354,352,344,340,355,351,339 0
388 352,344,340,355,351,339,381,345,384,356,368,380,362,341,360,386,383,363,342,385,349,361,343,382,353,350,338,357,379,347,337M,358,359,354 0
389 354,376,352,344,340,355,351,339,372,381,345,384,375,356,380,341,377,386,383,342,385,378,349,371,373,343,382,353,350,338,357,374,379,347,337M,358,369,370 0
395 347,337M,358,354,352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357 0
402 343,353,350,338,357,347,337M,358,394,354,390,352,368,396,362,344,340,360,391,355,363,351,339,388,345,392,361,356,395,341,342,359,393,349 0
404 342,349,343,353,350,338,357,347,337M,358,354,352,344,340,355,351,339,345,356,341 0
405 369,356,370,359,393,341,376,342,349,394,343,353,350,338,372,357,347,390,337M,358,375,354,368,396,362,360,377,391,363,388,352,378,344,340,371,355,373,392,351,339,361,395,345,374 0
407 355,392,351,339,361,395,345,356,359,393,341,342,381,349,384,394,343,353,350,338,357,347,380,390,337M,358,386,383,385,354,368,396,362,360,391,363,382,388,352,344,340,379 0
410 352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357,337M,358,354 0
412 354,352,344,340,355,351,339,345,356,341,342,349,347,343,353,350,338,357,337M,358 0
413 343,373,363,353,350,338,357,337M,358,374,369,361,370,354,376,352,359,344,340,355,351,339,345,372,356,375,341,342,377,349,378,368,362,360,371 0
414 349,378,368,362,360,371,343,373,363,353,350,338,357,337M,358,374,369,361,370,354,376,352,359,344,340,355,351,339,345,372,356,375,341,342,377 0
417 356,341,342,349,343,353,350,338,357,337M,358,354,352,344,340,355,351,339,345 0
419 345,388,356,392,341,395,368,362,342,360,363,349,393,343,353,350,338,361,357,337M,358,394,359,354,390,389,352,344,340,355,396,351,339,391 0
420 352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357,337M,358,354 0
425 354,352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357,337M,358,347 0
426 357,375,337M,358,382,377,379,354,378,371,373,352,344,340,355,351,339,374,345,370,381,356,376,384,341,342,386,349,383,372,385,343,353,350,338 0
429 349,343,353,350,338,357,337M,358,354,352,344,340,355,351,339,345,356,341,342 0
430 341,342,349,343,353,350,338,357,337M,358,354,352,344,340,355,351,339,345,356 0
431 356,396,391,341,342,388,349,392,395,343,368,362,353,350,338,360,357,363,337M,358,393,354,361,352,394,344,359,355,351,339,390,345 0
432 344,355,351,339,347,345,356,341,342,349,343,353,350,338,357,337M,358,354,340,352 0
1927 340,359,390,351,339,345,377,379,391,378,369,362,374,349,363,370,353,350,338,361M,337,358 0
1928 361M,359,390,339,345,379,391,395,378,369,381,362,374,349,370,350,338 0
1934 337,358,370,372,350,338,352,361M,344,340,355,396,359,356,390,377,373,339,342,345,360,379,391,395,384,363,369,381,362,374,349,354,394 0
1936 381,362,374,349,394,337,370,375,350,338,352,361M,388,396,341,359,356,390,377,373,339,378,345,360,379,391,376,395,353,384,363,369,386 0
1937 395,385,353,384,363,354,369,386,358,372,381,362,374,382,347,349,394,344,340,337,370,355,375,350,351,338,352,371,361M,392,388,368,396,341,359,342,343,356,390,393,377,357,373,380,339,378,345,360,379,391,376 0
1963 339,378,360,379,363,369,381,362,349,340,337,370,350,338,352,361M,388,359,377 0
1965 377,339,360,379,363,369,381,362,349,340,337,370,338,368,352,361M,359 0
1966 359,377,339,360,379,363,369,381,362,349,340,337,370,338,368,352,361M 0
1968 338,352,361M,359,339,360,379,350,363,369,381,362,349,340,337,370 0
1970 362,349,368,340,337,370,338,352,361M,377,359,339,360,379,350,363,369,381 0
1972 350,363,369,381,362,349,368,340,337,370,338,352,361M,359,339,360,379 0
1973 360,379,363,369,381,362,349,368,340,337,370,338,352,377,361M,359,339 0
1974 339,350,360,379,363,369,381,362,349,368,340,337,370,338,352,361M,359 0
2000 391,363,369,362,349,396M,338,390 0
2001 390,391,363,369,362,349,396M,338 0