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

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