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.02011

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,342,375,351,352,377,372,350,356,358,339,353,349M,376,374,355,369,338,371,344,357,345,378,354,373,370 0
381 347,360,357,345,378,380,386,361,354,373,370,381,362,341,363,342,375,382,379,351,352,372,350,340,356,358,339,343,337M,383,385,353,349,376,374,355,384,338,371,359,344 0
382 338,371,344,347,357,345,378,386,354,373,370,381,341,377,342,375,382,379,351,352,372,350,340,356,358,339,343,369,337M,383,385,353,349,376,374,355,384 0
383 374,355,359,384,338,360,371,344,361,347,362,357,363,345,378,386,354,373,370,381,341,377,342,375,351,352,372,350,340,356,358,339,368,343,337M,385,353,349,376 0
384 339,343,337M,353,349,355,338,344,347,357,345,354,341,342,351,352,350,340,356,358 0
385 393,395,352,368,390,350,340,356,358,376,339,374,343,337M,359,353,349,360,371,394,355,361,338,362,363,344,378,373,370,347,392,396,357,377,345,375,354,341,391,342,372,369,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,357,368,345,354,380,384,341,342,359,351,352,360,350,340,356,382,386,361,358,379,381,339,362,343,337M,363,353,349,355,383,338 0
389 372,369,383,338,344,385,347,376,357,374,345,354,380,384,341,371,342,351,352,350,340,356,378,382,386,358,373,370,379,381,339,343,337M,377,353,375,349,355 0
390 391,337M,353,349,388,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,356,372,369,358,383,339,343,337M,353,349,385,355,376,374,338,380,384,371,344,347,357,345,354,378,382,386,341,373,370,379,381,342 0
394 354,378,382,386,341,373,370,379,381,342,377,375,351,352,350,340,356,372,369,358,383,339,343,337M,353,349,385,355,376,374,338,380,384,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,347,378,373,370,357,345,354,377,375,341,342,372,369,351,352,350,340,356,358,339,343,376,337M,374,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,355,388,393,395,338,390,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,342,388,350,356,393,395,351,352,390,340,353,358,368,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,349,360,371,361,392,362,396,347,338,363,357,378,344,373,370,354,391,377,375,345,388,393,395,341,372,369,390,342,350,356,351,368,352,340,353,376,358,374,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,345,388,393,395,341,390,342,350,356,351,368,352 0
407 342,350,356,351,368,352,340,382,386,353,379,381,358,394,339,343,359,355,337M,349,360,361,383,392,362,396,347,338,363,357,344,385,354,391,345,388,380,384,393,395,341,390 0
408 345,380,384,376,341,374,342,350,356,351,371,352,340,382,386,353,379,381,358,339,343,355,337M,378,373,370,349,377,375,383,347,338,357,372,369,344,385,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,338,376,374,368,371,357,344,359,354,360,345,378,361,373,370,341,362,342,377,363,350,375,356,351,352,340,372,369 0
414 356,351,352,340,372,369,353,358,339,343,355,337M,349,338,376,374,368,371,357,344,359,354,360,345,378,361,373,370,341,362,342,377,363,350,375 0
415 341,342,350,356,351,352,340,353,358,339,343,355,337M,349,338,357,344,354,345 0
416 361,388,362,393,395,345,363,390,341,342,350,356,351,352,394,340,353,358,339,343,355,368,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 338,373,370,377,375,357,344,363,354,372,369,345,341,376,342,374,350,356,351,352,371,340,353,358,339,343,355,337M,349,378 0
419 339,343,360,355,337M,391,349,361,338,388,362,393,395,390,357,344,363,354,345,394,341,342,368,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,361,339,388,343,355,362,337M,393,395,349,390,338,363,357,344,394,354,345,368,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 337M,385,349,338,378,373,370,384,377,375,357,344,354,372,345,382,386,379,381,341,342,350,376,356,374,351,352,340,383,353,371,358,339,343,355 0
427 340,383,353,371,358,339,343,355,337M,385,380,349,338,378,373,370,384,377,375,369,357,344,347,354,372,345,382,386,379,381,341,342,350,376,356,374,351,352 0
428 350,356,368,351,352,340,353,392,396,358,339,359,343,355,337M,360,349,391,338,361,388,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,361,388,353,362,358,393,395,339,343,355,390,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 347,358,339,363,343,355,337M,349,383,338,385,368,380,357,344,354,384,359,345,360,341,342,361,350,340,356,382,386,362,351,379,381,352,353 0
439 362,351,376,379,381,352,374,353,358,339,371,363,343,355,337M,349,383,338,378,373,370,385,368,357,377,344,375,369,354,384,359,345,372,360,341,342,361,350,340,382,386 0
441 341,342,361,350,340,382,362,351,347,381,352,353,358,339,371,363,343,355,337M,349,383,338,380,370,368,357,344,369,354,384,359,345,372,360,356 0
1465 359,345,372,360,356,386,341,376,379,374,394,342,361M,350,340,382,362,351,347,381,352,353,358,339,371,392,363,396,343,355,337,378,349,373,383,385,338,380,391,377,375,370,388,368,393,395,357,344,369,390,354,384 0
1529 393,395,357,390,344,369,354,384,359,345,372,360,356,386,341,376,379,374,394,342,361,350,340,362,351,347,381,352,353,358,339,371,392,363,396,343,355,337,378,349M,373,385,338,380,391,377,375,370,388,368 0
1930 391,377,375,388,395,390,369,354,359,345,356,341,376,379,361M,350,340,362,351,381,352,353,339,363,355,337,349,338 0
1933 363,355,337,349,370,338,391,388,390,372,369,360,386,359,374,394,345,341,376,379,361M,350,340,362,381,352,396,339 0
1936 396,339,363,337,377,375,349,370,338,384,391,395,388,390,369,360,356,386,359,374,394,345,341,376,379,361M,350,353,378,362,373,381,352 0
1937 361M,350,353,378,362,373,381,352,368,396,355,393,357,344,339,363,337,377,375,349,354,370,338,382,384,391,395,342,372,388,347,390,369,360,356,386,351,358,359,374,371,392,394,345,343,340,341,376,379,385,380 0