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 = 359 
WHERE 
  cscart_products_categories.product_id IN (
    421, 443, 1971, 1959, 1930, 1960, 321, 
    436, 438, 437, 1961, 1931, 381, 1529, 
    1465, 1932, 1962, 1933, 1935, 1958, 
    428, 406, 439, 390, 1969, 1929, 398, 
    1964, 434, 383, 1927, 435, 419, 403, 
    324, 1965, 440, 1966, 431, 1928, 1973, 
    1968, 1963, 327, 1934, 385, 405, 413, 
    1970, 1937, 433, 414, 407, 402, 1972, 
    388, 1974, 442, 1936, 416, 326, 441, 
    1957
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01528

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "219.13"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "36.69"
      },
      "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": 36,
            "filtered": "39.88",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,443,1971,1959,1930,1960,321,436,438,437,1961,1931,381,1529,1465,1932,1962,1933,1935,1958,428,406,439,390,1969,1929,398,1964,434,383,1927,435,419,403,324,1965,440,1966,431,1928,1973,1968,1963,327,1934,385,405,413,1970,1937,433,414,407,402,1972,388,1974,442,1936,416,326,441,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "7.34",
              "prefix_cost": "138.42",
              "data_read_per_join": "586"
            },
            "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": 36,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "36.69",
              "eval_cost": "7.34",
              "prefix_cost": "182.45",
              "data_read_per_join": "586"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
321 359,362,349M 0
324 340,349,393,351,360,361,357,359,363,358,355,352,395,338M,396,394,391,353,388,362,390,356,368,354,350,392 0
326 354,385,350,379,392,380,349M,371,384,386,393,351,360,372,389,361,357,359,374,363,358,355,381,352,395,396,369,383,394,378,391,373,382,353,370,388,362,375,377,376,390,356,368 0
327 375,377,376,356,354,385,350,379,380,349M,371,384,386,351,360,372,361,357,359,374,363,358,355,381,352,369,383,378,373,382,353,370,362 0
381 353,370,362,340,375,339,341,376,342,356,344,354,385,350,337M,379,338,343,380,349,371,384,386,351,360,372,361,357,345,359,374,363,358,355,381,352,347,383,378,373,382 0
383 378,373,368,377,353,370,362,340,375,339,341,376,342,356,344,354,385,350,337M,338,343,349,371,384,386,351,360,372,361,357,345,359,374,363,358,355,381,352,347 0
385 358,355,352,390,347,378,373,368,392,377,353,370,393,362,340,375,339,341,376,342,356,395,344,354,396,394,350,337M,391,338,343,369,349,371,351,360,372,388,361,357,345,359,374,363 0
388 343,383,349,381,351,360,361,357,345,359,382,363,358,355,352,347,368,353,379,362,340,339,341,380,385,342,356,344,354,350,384,386,337M,338 0
390 350,337M,388,338,343,349,351,360,390,361,357,345,359,363,358,355,352,347,392,368,393,353,395,362,340,339,341,396,394,342,356,391,344,354 0
398 394,342,356,391,344,354,350,337M,388,338,343,349,351,360,390,361,357,345,359,389,363,358,355,352,347,392,368,393,353,395,362,340,339,341,396 0
402 395,362,340,339,341,396,394,342,356,391,344,354,350,337M,388,338,343,349,351,360,390,361,357,345,359,363,358,355,352,347,392,368,393,353 0
403 368,393,395,362,394,388,360,361,359M,363,392 0
405 369,371,372,392,374,353,368,393,340,339,341,396,342,356,378,391,395,362,344,373,354,394,350,377,337M,370,338,343,375,349,376,351,388,390,357,345,358,355,352,360,361,347,359,363 0
406 360,361,347,359,363,392,353,368,393,340,339,341,396,342,356,391,395,362,344,354,394,350,337M,338,343,349,351,388,390,357,345,358,355,352 0
407 388,390,357,384,386,345,358,355,352,360,383,361,381,347,359,363,382,392,353,368,393,340,339,341,396,342,356,391,395,362,344,354,379,394,350,337M,380,385,338,343,349,351 0
413 337M,338,343,349,351,369,357,371,345,372,358,355,374,352,360,361,359,363,378,373,353,377,368,370,340,339,341,375,342,356,376,362,344,354,350 0
414 362,344,354,350,337M,338,343,349,351,369,357,371,345,372,358,355,374,352,360,361,359,363,378,373,353,377,368,370,340,339,341,375,342,356,376 0
416 340,339,341,342,356,388,390,362,344,354,350,337M,338,343,349,351,357,345,392,358,355,352,360,361,393,359,363,396,391,395,353,394,368 0
419 391,395,353,394,368,340,339,341,342,356,388,390,362,344,354,350,337M,338,343,349,389,351,357,345,392,358,355,352,360,361,393,359,363,396 0
421 359,363,396,391,395,353,394,368,340,339,341,342,356,388,390,362,344,354,350,337M,338,343,349,351,357,345,392,358,355,352,360,361,393 0
428 392,358,355,352,360,361,393,359,363,396,391,395,347,353,394,368,340,339,341,342,356,388,390,362,344,354,350,337M,338,343,349,351,357,345 0
431 343,349,351,357,345,392,358,355,352,360,361,393,359,363,396,391,395,353,394,368,339,341,342,356,388,390,362,344,354,350,337M,338 0
433 360,361,359M,363,368,362 0
434 354,380,385,350,337M,362,338,343,384,386,349,351,357,345,383,358,381,355,352,382,347,360,361,359,363,340,353,339,341,342,356,368,379,344 0
435 368,379,380,385,362,392,384,386,349M,351,393,383,381,396,352,382,391,395,360,394,361,359,363,388,390 0
436 368,362,360,361,359M,363 0
437 360,361,359M,363,368,362 0
438 360,361,359M,363,368,362 0
439 339,341,370,342,375,344,376,354,350,379,337M,338,385,343,360,361,359,363,357,345,369,358,371,384,386,349,355,372,351,374,383,381,368,352,382,340,378,353,373,362,377 0
440 373,362,388,390,377,370,375,376,392,360,361,359M,363,393,369,371,372,396,374,391,395,368,394 0
441 368,353,356,339,341,362,342,344,354,370,380,350,337M,338,343,357,345,360,358,384,361,347,349,355,351,359,363,369,383,371,381,372,352,382,340 0
442 378,372,382,368,373,377,362,379,375,376,370,380,385,386,360,384,361,359M,363,374,369,383,371,381 0
443 359M,363,368,362,360,361 0
1465 352,394,374,369,383,340,360,371,381,361M,378,372,353,359,363,356,382,388,390,339,341,373,342,344,377,354,368,350,379,337,375,338,376,370,380,385,392,343,362,357,393,345,358,386,347,349,355,396,351,391,395,384 0
1529 349M,355,396,351,391,395,384,352,394,374,369,340,360,371,381,361,378,372,353,359,363,356,388,390,339,341,373,342,344,377,354,368,350,379,337,375,338,376,370,380,385,392,343,362,357,393,345,358,386,347 0
1927 345,358,349,351,391,374,369,340,361M,378,353,359,363,390,339,377,350,379,337,338,370,362 0
1928 379,338,370,362,345,395,349,391,381,374,369,361M,378,359,390,339,350 0
1929 337,350,379,338,352,345,349,388,391,381,373,363M,369,359,390,377,339 0
1930 390,377,339,355,337,362,350,379,351,338,395,352,356,345,340,341,349,353,388,391,381,361M,354,363,375,369,376,359 0
1931 369,376,359,396,390,339,337,360,371,362,350,372,379,338,395,342,374,345,340,349,353,388,391,381,361M,380,385,363 0
1932 388,391,381,369,377,359,384,390,394,339,362M,350,379,352,338,378,345,349 0
1933 345,361M,349,386,363,388,391,376,381,370,355,396,369,359,337,390,394,339,360,372,362,350,341,379,352,338,374,340 0
1934 338,374,340,345,361M,349,358,363,391,377,381,370,384,355,396,369,359,337,390,394,356,339,395,344,360,372,373,342,362,350,354,379,352 0
1935 342,393,362,350,379,380,352,338,374,340,345,388,376,361M,349,363,391,381,384,369,359,337,390,394,339,395,344,360,372 0
1936 339,375,395,360,362,350,379,352,386,338,374,345,388,377,376,361M,349,370,363,396,391,381,384,369,356,359,341,378,353,337,373,390,394 0
1937 356,344,359,357,341,354,378,372,385,353,337,373,390,394,347,342,339,375,395,360,393,380,340,382,362,350,379,352,358,386,338,374,351,371,355,345,388,377,376,361M,349,370,363,368,396,391,381,384,392,343,369 0
1957 381,369,359,331,337,339,360,340,362,379,352,338,377,361M,349,370,363,368 0
1958 377,361M,349,370,363,368,381,369,359,337,339,360,340,362,379,352,338,388 0
1959 377,361M,349,370,363,368,381,369,359,350,337,339,360,340,362,379,352,338 0
1960 340,362,379,352,338,378,377,361M,349,370,363,368,381,369,359,337,339,360 0
1961 360,340,362,379,338,378,377,361M,349,370,363,368,381,350,369,359,337,339 0
1962 359,337,339,360,352,390,340,362,379,338,377,361M,349,370,363,381,350,369,388 0
1963 350,369,388,359,337,339,360,352,340,362,379,338,378,377,361M,349,370,363,381 0
1964 363,381,369,359,337,339,360,340,362,379,338,378,368,377,361M,349,370 0
1965 377,361M,349,370,363,381,369,359,352,337,339,360,340,362,379,338,368 0
1966 338,368,377,361M,349,370,363,381,369,359,352,337,339,360,340,362,379 0
1968 340,362,379,350,338,361M,349,370,363,381,369,359,352,337,339,360 0
1969 337,339,360,368,340,362,379,350,338,361M,349,370,363,381,369,359,352 0
1970 369,359,352,337,339,360,368,340,377,362,379,350,338,361M,349,370,363,381 0
1971 381,369,359,352,337,339,360,368,340,377,362,379,350,338,361M,349,370,363 0
1972 361M,349,370,363,381,369,359,352,337,339,360,368,340,362,379,350,338 0
1973 361M,349,370,363,381,369,359,352,337,339,360,377,368,340,362,379,338 0
1974 340,362,379,338,361M,349,370,363,381,369,359,352,337,339,360,350,368 0