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, 1465, 1932, 1962, 1933, 1935, 
    1958, 428, 415, 391, 406, 329, 439, 390, 
    1969, 393, 394, 1929, 396, 397, 398, 
    399, 422, 1964
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00871

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "189.18"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "23.07"
      },
      "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": 23,
            "filtered": "25.08",
            "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,1465,1932,1962,1933,1935,1958,428,415,391,406,329,439,390,1969,393,394,1929,396,397,398,399,422,1964))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.61",
              "prefix_cost": "138.42",
              "data_read_per_join": "369"
            },
            "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": 23,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "23.07",
              "eval_cost": "4.61",
              "prefix_cost": "166.11",
              "data_read_per_join": "369"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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