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 = 388 
WHERE 
  cscart_products_categories.product_id IN (
    421, 1930, 1931, 1529, 1465, 1932, 1962, 
    1933, 1935, 1958, 428, 406, 390, 1929, 
    398, 435, 419, 403, 324, 440, 431, 1963, 
    385, 405
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00757

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "173.46"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "15.93"
      },
      "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": 15,
            "filtered": "17.31",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,1930,1931,1529,1465,1932,1962,1933,1935,1958,428,406,390,1929,398,435,419,403,324,440,431,1963,385,405))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "3.19",
              "prefix_cost": "138.42",
              "data_read_per_join": "254"
            },
            "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": 15,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "15.93",
              "eval_cost": "3.19",
              "prefix_cost": "157.53",
              "data_read_per_join": "254"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
324 359,357,361,363,393,350,338M,396,351,388,340,390,395,349,362,360,368,394,354,391,353,355,358,392,352,356 0
385 343,373,358,392,352,356,370,359,357,371,347,341,342,361,363,339,393,350,376,344,338,396,351,369,345,388,337M,340,390,377,395,349,362,378,374,375,360,368,394,354,391,353,355,372 0
390 360,368,394,354,391,353,355,343,358,392,352,356,359,357,347,341,342,361,363,339,393,350,344,338,396,351,345,388,337M,340,390,395,349,362 0
398 395,349,362,389,360,368,394,354,391,353,355,343,358,392,352,356,359,357,347,341,342,361,363,339,393,350,344,338,396,351,345,388,337M,340,390 0
403 388,395,362,360,368,394,392,359M,361,363,393 0
405 393,345,337M,340,372,390,373,349,388,370,395,371,362,354,391,353,355,343,360,358,368,394,376,352,356,357,392,347,369,341,342,359,339,377,350,378,374,361,344,338,363,375,396,351 0
406 350,361,344,338,363,396,351,393,345,337M,340,390,349,388,395,362,354,391,353,355,343,360,358,368,394,352,356,357,392,347,341,342,359,339 0
419 341,342,359,339,350,361,344,338,363,396,351,389,393,345,337M,340,390,349,388,395,362,354,391,353,355,343,360,358,368,394,352,356,357,392 0
421 352,356,357,392,341,342,359,339,350,361,344,338,363,396,351,393,345,337M,340,390,349,388,395,362,354,391,353,355,343,360,358,368,394 0
428 354,391,353,355,343,360,358,368,394,352,356,357,392,341,342,359,339,350,361,344,338,363,396,351,393,345,337M,340,390,349,388,395,362,347 0
431 395,362,354,391,353,355,343,360,358,368,394,352,356,357,392,341,342,359,339,350,361,344,338,363,396,351,393,345,337M,390,349,388 0
435 390,383,380,349M,388,385,379,395,362,391,384,360,368,394,352,392,359,382,386,361,381,363,396,351,393 0
440 377,361,363,374,396,393,375,390,372,388,373,395,370,362,391,371,360,368,394,376,392,369,359M 0
1465 337,369,359,381,378,351,347,377,361M,363,374,383,396,380,393,349,375,354,385,353,355,390,379,343,372,358,388,373,356,384,357,395,370,362,391,341,371,352,342,339,360,368,394,350,344,340,338,376,382,392,386,345 0
1529 340,344,338,376,392,386,345,337,369,359,381,378,351,347,377,361,363,374,396,380,393,349M,375,354,385,353,355,390,379,343,372,358,388,373,356,384,357,395,370,362,391,341,371,352,342,339,360,368,394,350 0
1929 339,350,338,345,337,369,359,381,377,363M,349,390,379,388,373,391,352 0
1930 391,352,340,376,339,350,338,351,345,337,369,361M,359,381,375,354,377,353,355,363,349,390,356,379,395,388,362,341 0
1931 342,379,395,360,388,362,391,340,376,339,350,338,374,396,380,345,337,369,385,361M,359,381,372,353,363,349,371,390 0
1932 349,394,390,379,388,362M,352,378,391,339,350,338,345,377,369,359,381,384 0
1933 341,349,360,394,386,390,379,388,362,352,340,376,391,339,374,396,350,337,361M,338,355,372,345,370,369,359,381,363 0
1935 384,372,345,369,359,381,363,342,344,395,349,360,394,390,379,388,362,393,352,340,376,380,391,339,374,350,337,361M,338 0
1958 370,368,337,361M,338,369,359,381,363,349,360,379,388,362,352,340,377,339 0
1962 350,377,339,370,337,361M,338,369,359,381,363,390,349,360,379,388,362,352,340 0
1963 388,362,352,340,350,377,339,370,337,361M,338,378,369,359,381,363,349,360,379 0