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 = 351 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 1930, 400, 424, 
    381, 1529, 401, 1465, 428, 415, 391, 
    406, 329, 439, 390, 393, 394, 396, 397, 
    398, 399, 422, 434, 383, 412, 1927, 435, 
    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.01690

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "229.55"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "41.42"
      },
      "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": 41,
            "filtered": "45.02",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,1930,400,424,381,1529,401,1465,428,415,391,406,329,439,390,393,394,396,397,398,399,422,434,383,412,1927,435,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": "8.28",
              "prefix_cost": "138.42",
              "data_read_per_join": "662"
            },
            "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": 41,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "41.42",
              "eval_cost": "8.28",
              "prefix_cost": "188.13",
              "data_read_per_join": "662"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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