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.01188

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,388,355,351,359,392,395,356,393,349,368,353,350,338M,394,362,360,357,363,358 0
383 368,384,353,350,338,362,360,357,347,363,337M,358,375,386,377,354,385,361,378,371,352,373,344,340,355,351,339,359,374,345,370,356,376,341,342,349,381,372,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 394,341,342,372,368,390,362,349,360,363,375,343,396,353,350,338,391,357,377,347,337M,358,388,361,378,371,392,354,373,395,359,374,352,369,344,340,355,370,393,351,339,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,381,351,339,384,345,356,368,380,386,362,341,360,383,385,363,342,349,382,361,343,353,350,338,379,357,347,337M,358,359,354 0
389 354,376,352,344,340,355,381,351,339,372,384,345,375,356,380,386,341,377,383,385,342,378,349,371,373,382,343,353,350,338,379,357,374,347,369,337M,358,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,394,337M,358,390,354,368,396,352,391,362,344,340,360,355,363,351,339,388,345,392,395,361,356,341,342,393,359,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,393,359,341,376,342,349,394,343,353,350,338,372,357,390,347,337M,358,375,368,396,354,391,362,360,377,363,388,352,378,344,340,371,392,355,373,351,339,395,361,345,374 0
407 392,355,351,339,395,361,345,356,393,359,341,342,381,349,384,394,343,353,350,338,357,380,390,347,386,337M,358,383,385,368,396,354,391,362,360,363,382,388,352,379,344,340 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,368,378,362,360,371 0
414 349,368,378,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,392,356,395,341,368,362,342,360,363,349,393,343,353,350,338,361,357,337M,358,394,359,354,390,389,352,344,340,396,355,391,351,339 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,382,337M,358,379,377,354,378,371,373,352,344,340,355,351,339,374,345,370,381,384,356,376,341,342,386,383,349,385,372,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 396,356,391,341,388,342,392,349,395,368,343,362,353,350,338,360,357,363,337M,358,393,354,361,394,352,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,379,391,345,377,378,369,362,374,349,363,370,353,350,338,361M,337,358 0
1928 361M,359,390,339,379,391,345,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,390,356,377,373,339,342,379,391,345,360,395,384,369,363,381,362,374,349,394,354 0
1936 381,362,374,349,394,337,370,375,350,338,352,361M,388,396,341,359,390,356,377,373,339,378,379,391,345,360,376,395,353,384,369,386,363 0
1937 395,385,353,384,369,386,363,354,358,381,372,382,362,374,347,349,394,344,340,337,370,355,375,350,351,338,352,371,392,361M,388,368,396,341,359,342,390,393,343,356,377,380,357,373,339,378,379,391,345,360,376 0
1963 339,378,379,360,369,363,381,362,349,340,337,370,350,338,352,361M,388,359,377 0
1965 377,339,379,360,369,363,381,362,349,340,337,370,338,368,352,361M,359 0
1966 359,377,339,379,360,369,363,381,362,349,340,337,370,338,368,352,361M 0
1968 338,352,361M,359,339,379,360,350,369,363,381,362,349,340,337,370 0
1970 362,368,349,370,340,337,338,352,361M,377,359,339,379,360,350,369,363,381 0
1972 350,369,363,381,362,368,349,370,340,337,338,352,361M,359,339,379,360 0
1973 379,360,369,363,381,362,368,349,370,340,337,338,352,377,361M,359,339 0
1974 339,379,350,360,369,363,381,362,368,349,370,340,337,338,352,361M,359 0
2000 391,369,363,362,349,396M,338,390 0
2001 390,391,369,363,362,349,396M,338 0