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

Query time 0.01869

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "204.24"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "29.92"
      },
      "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": 29,
            "filtered": "32.52",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (427,408,1971,382,418,1959,1960,1961,381,1529,1465,1962,1933,1958,329,439,1969,393,394,396,1964,383,1927,1965,440,1966,1928,1973,1968,1963,327,1934,385,405,413,1970,1937,414,389,1972,426,1974,442,1936,326,441,322,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "5.98",
              "prefix_cost": "138.42",
              "data_read_per_join": "478"
            },
            "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": 29,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "29.92",
              "eval_cost": "5.98",
              "prefix_cost": "174.32",
              "data_read_per_join": "478"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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