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 = 350 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 1971, 382, 418, 1959, 1930, 
    400, 424, 1961, 1931, 381, 1529, 1465, 
    1932, 1962, 1933, 1935, 428, 415, 391, 
    406, 329
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00751

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "171.25"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "14.92"
      },
      "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": 14,
            "filtered": "16.22",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,424,1961,1931,381,1529,1465,1932,1962,1933,1935,428,415,391,406,329))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "2.98",
              "prefix_cost": "138.42",
              "data_read_per_join": "238"
            },
            "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": 14,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "14.92",
              "eval_cost": "2.98",
              "prefix_cost": "156.33",
              "data_read_per_join": "238"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
329 353,375,342,350,377,371,376,373,354,358,339,356,372,374,370,378,369,352,338,355,351,357,349M 0
381 351,386,344,357,349,382,361,340,353,375,342,350,371,362,347,376,373,379,345,354,358,337M,339,356,341,372,374,363,343,380,384,370,378,381,352,360,338,359,355,383,385 0
382 338,355,383,385,351,386,344,357,349,382,340,377,353,375,342,350,371,347,376,373,379,345,354,358,337M,339,356,341,372,369,374,343,384,370,378,381,352 0
391 352,338,355,351,344,357,349,340,353,342,350,347,345,354,358,337M,339,356,341,343 0
400 339,356,341,343,352,338,355,351,344,357,349,340,353,342,350,347,345,354,358,337M 0
406 360,354,358,359,368,395,337M,388,392,339,356,341,361,343,396,352,362,338,355,391,351,344,357,349,340,353,363,390,394,342,350,393,347,345 0
408 342,370,350,378,381,347,345,354,358,383,385,337M,339,356,386,341,382,343,377,375,352,371,376,373,379,338,355,351,344,357,380,349,372,369,340,374,353,384 0
415 349,340,353,342,350,345,354,358,337M,339,356,341,343,352,338,355,351,344,357 0
418 372,369,374,351,344,357,349,370,378,340,353,342,350,345,354,358,337M,377,339,356,341,375,343,371,376,373,352,363,338,355 0
421 393,352,363,338,355,360,359,368,395,351,388,392,344,357,349,340,353,361,342,396,350,345,362,354,358,391,337M,339,356,341,343,390,394 0
424 343,352,347,338,355,351,344,357,349,340,353,342,350,345,354,358,337M,339,356,341 0
427 337M,339,356,341,384,372,369,343,374,381,370,378,383,352,385,347,338,355,386,351,382,344,357,349,340,353,377,342,379,350,375,345,371,354,358,376,373,380 0
428 345,354,358,390,394,337M,393,339,356,363,341,360,359,343,368,395,388,392,352,347,361,338,355,396,351,344,357,362,349,340,391,353,342,350 0
1465 340,391,353,371,342,376,373,350,380,345,354,358,384,390,394,337,372,369,393,374,381,339,356,363,341,360,370,359,378,383,343,368,385,395,388,392,386,352,347,382,361M,338,355,396,351,344,357,377,362,349,379,375 0
1529 351,344,357,377,362,349M,379,375,340,391,353,371,342,376,373,350,380,345,354,358,384,390,394,337,372,369,393,374,381,339,356,363,341,360,370,359,378,343,368,385,395,388,392,386,352,347,361,338,355,396 0
1930 352,361M,338,355,351,377,362,349,379,375,340,391,353,376,350,345,354,390,337,369,381,339,356,363,341,359,395,388 0
1931 395,388,396,361M,338,371,362,342,349,379,380,340,391,353,376,350,372,345,374,390,360,337,369,381,385,339,363,359 0
1932 381,339,359,352,388,338,377,362M,349,379,384,394,391,350,378,345,390,369 0
1933 345,363,390,369,381,339,355,396,359,352,388,361M,338,340,362,349,376,379,394,370,391,372,374,350,341,360,386,337 0
1935 374,350,360,337,345,395,363,344,390,369,381,339,359,352,388,361M,342,380,393,338,384,340,362,349,376,379,394,391,372 0
1959 362,349,379,350,360,337,363,369,381,339,377,359,352,361M,338,368,340,370 0
1961 338,368,340,370,362,349,379,350,360,337,363,369,381,339,377,359,361M,378 0
1962 361M,338,340,370,362,349,379,390,350,360,337,388,363,369,352,381,339,377,359 0
1971 377,359,361M,368,338,340,370,362,349,379,350,360,337,363,369,352,381,339 0