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

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,357,394,362,360,358,363 0
383 368,384,353,350,338,357,362,360,347,358,375,363,337M,377,386,354,385,361,378,371,373,352,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,358,337M,354,352,344,340,355,351,339,345,356,341,342 0
385 394,341,372,342,368,390,362,349,360,375,363,343,396,353,350,338,357,377,391,347,358,337M,388,361,378,371,373,392,354,395,359,374,352,369,344,340,370,355,393,351,339,376,345,356 0
387 345,356,341,342,349,343,353,350,338,357,347,358,337M,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,357,379,347,358,337M,359,354 0
389 376,354,352,344,340,355,372,381,351,339,384,345,375,356,380,377,386,341,383,385,342,378,371,349,373,382,343,353,350,338,357,374,379,347,358,369,337M,370 0
395 347,358,337M,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,358,394,337M,390,354,368,396,352,391,362,344,340,360,355,363,351,339,388,345,392,356,395,361,341,342,393,359,349 0
404 342,349,343,353,350,338,357,347,358,337M,354,352,344,340,355,351,339,345,356,341 0
405 369,356,370,393,359,341,376,342,349,394,343,372,353,350,338,357,390,347,358,337M,375,368,396,354,377,391,362,360,363,388,378,352,371,344,340,355,373,392,351,339,395,361,345,374 0
407 355,392,351,339,395,361,345,356,393,359,341,342,381,349,384,394,343,353,350,338,357,380,390,347,358,386,337M,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,358,337M,354 0
412 354,352,344,340,355,351,339,345,356,341,342,349,347,343,353,350,338,357,358,337M 0
413 373,343,363,353,350,338,357,358,374,337M,369,370,361,354,376,352,359,344,340,355,351,339,372,345,356,375,341,377,342,349,378,368,371,362,360 0
414 349,378,368,371,362,360,373,343,363,353,350,338,357,358,374,337M,369,370,361,354,376,352,359,344,340,355,351,339,372,345,356,375,341,377,342 0
417 356,341,342,349,343,353,350,338,357,358,337M,354,352,344,340,355,351,339,345 0
419 345,388,356,392,395,341,368,362,342,360,363,349,393,343,353,350,338,357,361,358,337M,394,359,354,390,389,352,344,340,355,396,391,351,339 0
420 352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357,358,337M,354 0
425 354,352,344,340,355,351,339,345,356,341,342,349,343,353,350,338,357,358,337M,347 0
426 357,375,358,382,337M,377,379,354,378,371,373,352,344,340,355,374,351,339,345,370,381,356,376,384,341,342,386,383,349,372,385,343,353,350,338 0
429 349,343,353,350,338,357,358,337M,354,352,344,340,355,351,339,345,356,341,342 0
430 341,342,349,343,353,350,338,357,358,337M,354,352,344,340,355,351,339,345,356 0
431 356,396,391,341,388,342,392,349,395,368,343,362,353,350,338,360,357,363,358,337M,393,354,361,394,352,344,355,359,351,339,390,345 0
432 344,355,351,339,347,345,356,341,342,349,343,353,350,338,357,358,337M,354,340,352 0
1927 340,359,390,351,339,377,379,391,345,378,369,374,362,349,363,370,353,350,338,358,361M,337 0
1928 361M,359,390,339,379,391,345,395,378,369,381,374,362,349,370,350,338 0
1934 358,370,337,372,350,338,352,361M,344,340,355,396,359,356,390,377,373,339,342,379,391,345,360,395,384,369,363,381,374,362,349,394,354 0
1936 381,374,362,349,394,370,337,375,350,338,352,361M,388,396,341,359,356,390,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,372,381,374,382,362,347,349,394,370,344,340,337,355,375,350,351,338,371,352,392,361M,388,368,396,341,359,342,356,390,393,343,377,357,373,380,339,378,379,391,345,360,376 0
1963 339,378,379,360,369,363,381,362,349,370,340,337,350,338,352,361M,388,359,377 0
1965 377,339,379,360,369,363,381,362,349,370,340,337,338,368,352,361M,359 0
1966 359,377,339,379,360,369,363,381,362,349,370,340,337,338,368,352,361M 0
1968 338,352,361M,359,339,379,360,350,369,363,381,362,349,370,340,337 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,377,352,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