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 = 344 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 400, 424, 381, 
    1529, 401, 1465, 1935, 428, 415, 391, 
    406, 439, 390, 393, 394, 396, 397, 398, 
    399, 422, 434, 383, 412, 419, 430, 431, 
    432, 429, 384, 1934, 395, 420, 385, 405, 
    410
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01007

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "196.60"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "26.44"
      },
      "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": 26,
            "filtered": "28.74",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,400,424,381,1529,401,1465,1935,428,415,391,406,439,390,393,394,396,397,398,399,422,434,383,412,419,430,431,432,429,384,1934,395,420,385,405,410))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "5.29",
              "prefix_cost": "138.42",
              "data_read_per_join": "423"
            },
            "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": 26,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "26.44",
              "eval_cost": "5.29",
              "prefix_cost": "170.16",
              "data_read_per_join": "423"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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