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 = 341 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 1930, 400, 424, 
    381, 1529, 401, 1465, 1933, 428, 415, 
    391, 406, 439, 390, 393, 394, 396, 397, 
    398, 399, 422, 434, 383, 412, 419, 430, 
    431, 432, 429, 384, 395, 420, 385, 405, 
    410, 413, 417, 1937, 414, 425, 407, 389, 
    402, 388, 426, 409, 404, 1936, 387, 386, 
    416, 441, 322
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01841

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "223.52"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "38.68"
      },
      "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": 38,
            "filtered": "42.04",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,1930,400,424,381,1529,401,1465,1933,428,415,391,406,439,390,393,394,396,397,398,399,422,434,383,412,419,430,431,432,429,384,395,420,385,405,410,413,417,1937,414,425,407,389,402,388,426,409,404,1936,387,386,416,441,322))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "7.74",
              "prefix_cost": "138.42",
              "data_read_per_join": "618"
            },
            "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": 38,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "38.68",
              "eval_cost": "7.74",
              "prefix_cost": "184.84",
              "data_read_per_join": "618"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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