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 = 345 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 1930, 400, 424, 
    1931, 381, 1529, 401, 1465, 1932, 1933, 
    1935, 428, 415, 391, 406, 439, 390, 393, 
    394, 1929, 396, 397, 398, 399, 422, 434, 
    383, 412, 1927, 419, 430, 431, 432, 1928, 
    429
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01418

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "194.43"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "25.46"
      },
      "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": 25,
            "filtered": "27.67",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,1930,400,424,1931,381,1529,401,1465,1932,1933,1935,428,415,391,406,439,390,393,394,1929,396,397,398,399,422,434,383,412,1927,419,430,431,432,1928,429))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "5.09",
              "prefix_cost": "138.42",
              "data_read_per_join": "407"
            },
            "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": 25,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "25.46",
              "eval_cost": "5.09",
              "prefix_cost": "168.97",
              "data_read_per_join": "407"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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