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

Query time 0.01408

JSON explain

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

Result

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