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

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