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 = 377 
WHERE 
  cscart_products_categories.product_id IN (
    427, 408, 1971, 382, 418, 1959, 1930, 
    1960, 1961, 1529, 1465, 1932, 1962, 
    1958, 329, 439, 393, 394, 1929, 396, 
    1964, 383, 1927, 1965, 440, 1966, 1973, 
    1963, 327, 1934, 385, 405, 413, 1970, 
    1937, 414, 389, 426, 442, 1936, 326, 
    322, 1957
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.04583

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "198.21"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "27.17"
      },
      "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": 27,
            "filtered": "29.54",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (427,408,1971,382,418,1959,1930,1960,1961,1529,1465,1932,1962,1958,329,439,393,394,1929,396,1964,383,1927,1965,440,1966,1973,1963,327,1934,385,405,413,1970,1937,414,389,426,442,1936,326,322,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "5.43",
              "prefix_cost": "138.42",
              "data_read_per_join": "434"
            },
            "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": 27,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "27.17",
              "eval_cost": "5.43",
              "prefix_cost": "171.03",
              "data_read_per_join": "434"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
322 374,341,354,370,377,373,357,342,371,369,349M,372,378,350,344,356,352,345,338,339,353,358,355,351,376,375 0
326 359,376,375,385,361,389,374,354,381,370,395,384,390,377,379,373,382,383,357,386,391,371,369,380,392,349M,372,393,378,363,350,360,356,394,352,368,362,353,396,358,355,388,351 0
327 358,355,351,359,376,375,385,361,374,354,381,370,384,377,379,373,382,383,357,386,371,369,380,349M,372,378,363,350,360,356,352,362,353 0
329 356,352,353,358,355,351,376,375,342,374,354,370,377,373,338,357,339,371,369,349M,372,378,350 0
382 371,369,349,372,378,350,356,352,341,353,358,355,385,351,347,376,381,375,384,342,374,344,354,379,382,345,340,370,383,386,377,337M,343,373,338,357,339 0
383 337M,360,343,373,338,357,339,362,371,349,372,378,350,356,352,341,359,361,353,358,355,385,351,347,376,381,375,384,342,374,344,354,345,340,370,368,386,377,363 0
385 354,396,345,340,370,368,377,388,363,337M,360,369,343,373,338,357,339,362,371,349,372,378,395,350,390,356,352,341,359,361,353,391,358,392,355,351,393,347,376,394,375,342,374,344 0
389 376,375,386,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,349,372,378,350,356,352,341,385,353,358,379,380,381,382,355,383,351,384,347 0
393 358,379,380,381,382,355,383,351,384,347,376,375,386,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,349,372,378,350,356,352,341,385,353 0
394 385,353,358,379,380,381,382,355,383,351,384,347,376,375,386,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,349,372,378,350,356,352,341 0
396 349,372,378,350,356,352,341,353,358,355,351,347,376,375,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371 0
405 338,357,394,339,371,396,349,372,378,350,368,356,388,363,352,341,360,353,362,358,355,351,347,395,376,390,359,375,342,374,361,344,354,391,345,340,370,392,377,337M,369,393,343,373 0
408 370,377,337M,369,343,373,338,357,339,385,371,379,380,349,372,381,382,378,383,350,384,356,352,341,353,386,358,355,351,347,376,375,342,374,344,354,345,340 0
413 375,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,368,363,360,349,372,378,350,356,362,352,341,353,358,359,355,351,361,376 0
414 359,355,351,361,376,375,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,368,363,360,349,372,378,350,356,362,352,341,353,358 0
418 353,358,355,351,376,375,342,374,344,354,345,340,370,377,337M,369,343,373,338,357,339,371,363,349,372,378,350,356,352,341 0
426 378,350,356,352,341,353,358,355,351,385,376,375,379,381,382,342,374,383,344,354,384,345,340,370,377,337M,386,343,373,338,357,339,371,349,372 0
427 371,349,372,378,350,356,352,341,353,358,355,380,351,385,376,375,379,381,382,342,374,383,344,354,369,384,345,340,370,377,337M,386,347,343,373,338,357,339 0
439 377,337M,386,343,373,338,357,339,359,371,361,349,372,378,350,352,341,353,358,355,351,385,376,368,360,375,379,381,382,342,374,383,344,354,369,384,362,363,345,340,370 0
440 374,392,369,362,363,370,393,377,394,373,359M,396,371,361,372,388,395,390,376,368,360,375,391 0
442 383,376,368,384,360,375,374,369,386,362,363,370,377,373,359M,378,371,361,372,380,385,379,381,382 0
1465 385,344,354,347,345,340,379,381,382,391,383,392,337,376,368,384,343,360,375,393,338,357,339,374,369,386,394,356,362,363,370,349,377,396,350,373,352,341,388,359,378,353,371,361M,358,372,355,380,351,395,390,342 0
1529 395,390,342,385,344,354,347,345,340,379,381,391,392,337,376,368,384,343,360,375,393,338,357,339,374,369,386,394,356,362,363,370,349M,377,396,350,373,352,341,388,359,378,353,371,361,358,372,355,380,351 0
1927 361M,358,351,390,345,340,379,391,337,338,339,374,369,362,363,370,349,377,350,359,378,353 0
1929 359,390,381,345,379,391,337,338,339,369,373,363M,352,349,388,377,350 0
1930 363,352,349,388,355,377,353,350,361M,395,359,351,354,376,340,375,390,381,356,345,379,391,337,362,341,338,339,369 0
1932 362M,338,339,378,369,352,349,388,377,350,359,384,394,390,381,345,379,391 0
1934 373,345,379,372,391,362,363,338,358,339,355,369,342,361M,352,344,349,395,377,350,354,360,359,384,340,374,396,394,356,370,390,381,337 0
1936 356,341,370,390,381,337,373,345,379,391,378,353,362,363,338,388,339,369,361M,352,349,395,377,350,376,386,360,359,375,384,374,396,394 0
1937 374,380,396,394,356,341,370,390,372,381,337,382,373,385,345,358,379,347,391,355,378,353,351,342,392,362,363,344,338,368,343,388,339,393,357,369,361M,352,354,349,395,377,350,376,386,340,360,359,375,371,384 0
1957 340,360,359,370,381,337,379,362,363,338,368,331,339,369,361M,352,349,377 0
1958 349,377,340,360,359,370,381,337,379,388,362,363,338,368,339,369,361M,352 0
1959 339,369,361M,352,349,377,340,360,359,370,381,337,379,350,362,363,338,368 0
1960 362,363,338,368,339,369,361M,352,349,377,340,360,359,378,370,381,337,379 0
1961 381,350,337,379,362,363,338,368,339,369,361M,349,377,340,360,359,378,370 0
1962 370,381,350,337,379,390,362,363,352,338,339,369,361M,349,377,340,360,359,388 0
1963 388,370,381,350,337,379,362,363,352,338,339,369,361M,349,377,378,340,360,359 0
1964 378,340,360,359,370,368,381,337,379,362,363,338,339,369,361M,349,377 0
1965 369,361M,349,377,340,360,359,370,368,381,337,352,379,362,363,338,339 0
1966 362,363,338,339,369,361M,349,377,340,360,359,370,368,381,337,352,379 0
1970 337,352,379,362,363,338,339,369,361M,349,377,350,340,360,359,370,368,381 0
1971 370,368,381,337,352,379,362,363,338,339,369,361M,349,377,350,340,360,359 0
1973 370,368,381,337,352,379,362,363,338,339,369,361M,349,377,340,360,359 0