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 = 349 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 1971, 382, 418, 1959, 1930, 
    400, 1960, 321, 424, 1961, 1931, 381, 
    1529, 401, 2001, 1465, 1932, 1962, 1933, 
    1935, 1958, 428, 415, 391, 406, 329, 
    439, 390, 1969, 393, 394, 1929, 396, 
    397, 398, 399, 422
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00871

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "188.78"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "22.89"
      },
      "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.88",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,1960,321,424,1961,1931,381,1529,401,2001,1465,1932,1962,1933,1935,1958,428,415,391,406,329,439,390,1969,393,394,1929,396,397,398,399,422))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.58",
              "prefix_cost": "138.42",
              "data_read_per_join": "366"
            },
            "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.89",
              "eval_cost": "4.58",
              "prefix_cost": "165.89",
              "data_read_per_join": "366"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
321 362,359,349M 0
329 356,354,339,350,371,370,369,375,378,374,353,352,358,342,351,349M,338,357,377,373,372,376,355 0
381 340,376,355,361,344,356,384,354,339,381,350,371,370,347,379,362,386,341,360,375,378,374,353,359,352,345,358,382,342,343,351,349,380,363,337M,385,338,357,373,383,372 0
382 337M,385,338,357,373,383,372,340,376,355,344,356,384,354,339,381,350,371,369,370,347,379,386,341,375,378,374,353,352,345,358,382,342,343,351,377,349 0
390 363,342,388,343,392,351,349,393,337M,368,338,357,361,340,394,355,344,356,354,390,396,339,362,350,360,347,359,341,391,353,395,352,345,358 0
391 353,352,345,358,342,343,351,349,337M,338,357,340,355,344,356,354,339,350,347,341 0
393 377,341,385,353,373,383,372,352,345,358,342,343,376,351,349,337M,384,338,357,381,371,369,340,370,379,355,386,344,356,354,339,375,378,374,350,347,380,382 0
394 339,375,378,374,350,347,380,382,377,341,385,353,373,383,372,352,345,358,342,343,376,351,349,337M,384,338,357,381,371,369,340,370,379,355,386,344,356,354 0
396 355,344,356,354,339,375,378,374,350,347,377,341,353,373,372,352,345,358,342,343,376,351,349,337M,338,357,371,369,340,370 0
397 338,357,340,355,344,356,354,339,350,347,341,353,352,345,358,342,343,351,349,337M 0
398 351,391,349,337M,395,363,338,357,388,392,340,393,355,368,389,344,356,361,354,339,350,394,347,390,396,362,341,360,353,352,345,359,358,342,343 0
399 353,352,345,358,342,343,351,349,337M,338,357,340,355,344,356,354,339,350,347,341 0
400 341,353,352,345,358,342,343,351,349,337M,338,357,340,355,344,356,354,339,350,347 0
401 341,352,345,358,342,343,351,349,337M,338,340,344,339 0
406 350,344,347,359,339,391,395,363,353,388,341,392,393,368,352,345,358,342,361,343,351,357,349,394,337M,338,355,390,396,362,340,356,354,360 0
408 379,340,356,354,371,369,386,370,350,344,347,339,380,382,375,378,374,353,341,385,377,383,352,345,358,373,342,372,343,351,357,384,349,376,381,337M,338,355 0
415 337M,338,355,340,356,354,350,344,339,353,341,352,345,358,342,343,351,357,349 0
418 352,345,358,342,343,351,357,349,337M,371,369,338,370,355,340,356,354,363,350,375,344,378,374,339,377,353,341,373,372,376 0
421 362,360,352,345,358,342,343,359,351,357,349,391,337M,338,395,355,388,340,356,392,354,393,363,350,344,368,339,361,394,353,341,390,396 0
422 353,341,352,345,358,342,343,351,357,349,337M,338,355,340,356,354,350,344,339 0
424 339,353,341,347,352,345,358,342,343,351,357,349,337M,338,355,340,356,354,350,344 0
427 354,373,381,372,350,344,376,379,339,386,371,369,353,370,341,380,382,347,352,345,358,375,342,378,374,385,343,383,351,357,349,337M,377,338,355,384,340,356 0
428 394,338,355,340,356,390,396,354,362,350,360,344,339,359,391,353,395,341,388,392,347,393,363,352,345,358,342,368,343,351,357,361,349,337M 0
439 343,377,351,357,361,349,384,337M,373,381,338,372,355,340,376,354,379,362,386,350,360,344,339,359,371,369,370,382,353,341,375,378,374,385,383,363,352,345,358,342,368 0
1465 383,363,352,345,358,342,368,343,377,394,351,357,361M,349,384,337,356,390,396,373,381,338,372,355,340,376,354,379,362,386,350,360,344,380,391,339,359,371,369,370,395,382,388,392,347,353,341,393,375,378,374,385 0
1529 347,353,341,393,375,378,374,385,363,352,345,358,342,368,343,377,394,351,357,361,349M,384,337,356,390,396,373,381,338,372,355,340,376,354,379,362,386,350,360,344,380,391,339,359,371,369,370,395,388,392 0
1929 359,369,388,363M,352,345,377,349,337,390,373,381,338,379,350,391,339 0
1930 350,395,391,339,359,369,353,341,375,388,351,361M,363,352,345,356,377,349,355,340,337,376,390,354,381,362,338,379 0
1931 371,379,350,395,391,339,374,385,359,369,353,388,342,396,372,361M,363,345,349,360,340,337,376,380,390,381,362,338 0
1932 349,390,381,362M,338,379,378,350,391,339,359,369,394,384,388,352,377,345 0
1933 345,360,370,340,337,376,349,390,381,362,338,341,379,374,350,391,339,359,369,394,388,396,372,361M,355,386,363,352 0
1935 361M,363,352,380,345,360,340,337,376,393,349,395,390,381,362,338,379,342,374,350,384,391,339,359,369,394,388,344,372 0
1958 388,361M,363,352,370,360,340,337,368,349,381,362,338,379,339,359,377,369 0
1959 339,359,377,369,361M,363,352,370,360,340,337,368,349,381,362,338,350,379 0
1960 379,339,359,377,369,378,361M,363,352,370,360,340,337,368,349,381,362,338 0
1961 381,362,338,379,339,359,377,369,378,361M,363,370,360,340,337,368,349,350 0
1962 340,337,349,350,381,388,362,338,379,339,390,359,377,369,352,361M,363,370,360 0
1969 368,360,340,337,349,350,381,362,338,379,339,359,369,352,361M,363,370 0
1971 361M,363,370,368,360,340,337,349,350,381,362,338,379,377,339,359,369,352 0
2001 369,363,349,362,338,390,391,396M 0