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 = 340 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 1971, 382, 418, 1959, 1930, 
    400, 1960, 424, 1961, 1931, 381, 1529, 
    401, 1465, 1962, 1933, 1935, 1958, 428, 
    415, 391, 1729, 406, 439, 390, 1969, 
    393, 394, 396, 397, 398, 399, 422, 1964, 
    434, 383, 412
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00916

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "191.09"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "23.94"
      },
      "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": 23,
            "filtered": "26.02",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,1960,424,1961,1931,381,1529,401,1465,1962,1933,1935,1958,428,415,391,1729,406,439,390,1969,393,394,396,397,398,399,422,1964,434,383,412))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.79",
              "prefix_cost": "138.42",
              "data_read_per_join": "382"
            },
            "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": 23,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "23.94",
              "eval_cost": "4.79",
              "prefix_cost": "167.15",
              "data_read_per_join": "382"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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