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

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