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

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