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
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01205

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "195.04"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "25.73"
      },
      "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": 25,
            "filtered": "27.97",
            "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))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "5.15",
              "prefix_cost": "138.42",
              "data_read_per_join": "411"
            },
            "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": 25,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "25.73",
              "eval_cost": "5.15",
              "prefix_cost": "169.30",
              "data_read_per_join": "411"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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