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

Query time 0.00942

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "191.09"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "23.94"
      },
      "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": "26.02",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,1960,424,1961,1931,381,1529,401,1465,1962,1933,1935,1958,428,415,391,1729,406,439,390,1969,393,394,396,397,398,399,422,1964,434,383,412))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.79",
              "prefix_cost": "138.42",
              "data_read_per_join": "382"
            },
            "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.94",
              "eval_cost": "4.79",
              "prefix_cost": "167.15",
              "data_read_per_join": "382"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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