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 = 358 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 400, 424, 381, 
    1529, 401, 1465, 428, 415, 391, 406, 
    329, 439, 390, 393, 394, 396, 397, 398, 
    399, 422, 1728, 434, 383, 412, 1927, 
    419, 430, 324, 431, 432, 429, 384, 327, 
    1934, 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.01474

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "228.47"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "40.93"
      },
      "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": 40,
            "filtered": "44.49",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,400,424,381,1529,401,1465,428,415,391,406,329,439,390,393,394,396,397,398,399,422,1728,434,383,412,1927,419,430,324,431,432,429,384,327,1934,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": "8.19",
              "prefix_cost": "138.42",
              "data_read_per_join": "654"
            },
            "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": 40,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "40.93",
              "eval_cost": "8.19",
              "prefix_cost": "187.54",
              "data_read_per_join": "654"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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