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 = 356 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 382, 418, 1930, 400, 424, 
    381, 1529, 1465, 428, 415, 391, 406, 
    329, 390, 393, 394, 396, 397, 398, 399, 
    422, 434, 383, 412, 419, 430, 324, 431, 
    432, 429, 384, 327, 1934, 395, 420, 385, 
    405, 410, 413, 417, 1937, 414, 425, 407, 
    323, 389, 402, 388, 426, 409, 404, 325, 
    1936, 387, 386, 416, 326, 441, 322
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01329

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "227.55"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "40.51"
      },
      "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": 40,
            "filtered": "44.04",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,1930,400,424,381,1529,1465,428,415,391,406,329,390,393,394,396,397,398,399,422,434,383,412,419,430,324,431,432,429,384,327,1934,395,420,385,405,410,413,417,1937,414,425,407,323,389,402,388,426,409,404,325,1936,387,386,416,326,441,322))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "8.10",
              "prefix_cost": "138.42",
              "data_read_per_join": "648"
            },
            "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": 40,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "40.51",
              "eval_cost": "8.10",
              "prefix_cost": "187.04",
              "data_read_per_join": "648"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
322 341,356,354,374,338,344,378,351,375,371,353,355,342,376,372,350,339,349M,357,345,377,373,369,358,352,370 0
323 358,352,356,354,351,353,355,350,349M,357 0
324 349,357,395,388,394,361,396,358,352,356,338M,354,393,368,360,362,390,340,351,391,359,353,355,392,363,350 0
325 350,349M,357,358,352,356,351,353,355 0
326 377,373,369,380,363,353,379,389,355,370,383,395,388,394,350,374,361,386,349M,357,396,381,378,384,358,375,371,354,352,393,356,368,385,360,382,362,390,376,372,391,359,392,351 0
327 359,351,377,373,369,380,363,353,379,355,370,383,350,374,361,386,349M,357,381,378,384,358,375,371,354,352,356,385,360,382,362,376,372 0
329 376,372,351,377,373,369,353,355,370,338,350,374,349M,357,342,378,339,358,375,371,354,352,356 0
381 358,375,371,354,352,337M,356,341,359,376,372,380,363,344,343,379,351,347,383,373,353,355,370,361,386,338,381,340,350,374,349,357,384,345,342,378,385,339,360,382,362 0
382 345,342,378,385,339,382,358,375,371,354,352,337M,356,341,376,372,377,369,344,343,379,351,347,383,373,353,355,370,386,338,381,340,350,374,349,357,384 0
383 381,340,350,374,349,357,360,384,362,345,342,378,385,339,358,375,371,359,354,352,337M,356,341,363,376,372,377,344,343,351,361,347,368,373,353,355,370,386,338 0
384 355,338,340,350,349,357,345,342,339,358,354,352,337M,356,341,344,343,351,347,353 0
385 344,343,351,370,347,392,353,355,374,338,360,362,340,350,378,395,349,357,388,394,375,371,345,359,396,342,339,358,354,369,363,352,337M,356,376,372,393,341,377,390,361,368,373,391 0
386 344,343,351,347,353,355,338,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
387 337M,356,341,344,343,351,347,353,355,338,340,350,349,357,345,342,339,358,354,352 0
388 342,339,361,386,358,368,354,352,381,337M,356,341,382,384,385,360,362,344,343,380,351,347,353,359,355,379,338,383,340,363,350,349,357,345 0
389 349,357,345,373,342,339,370,386,358,354,352,381,337M,356,374,341,382,384,378,385,344,343,375,371,380,351,347,353,355,369,379,376,372,338,383,340,377,350 0
390 390,338,340,391,350,349,357,361,368,392,345,342,339,358,354,352,337M,356,395,341,388,394,360,362,396,344,343,359,351,347,353,393,355,363 0
391 347,353,355,338,340,350,349,357,345,342,339,358,354,352,337M,356,341,344,343,351 0
393 379,376,372,344,343,383,377,351,347,353,355,373,338,370,386,340,350,381,349,357,374,345,382,384,342,339,378,358,385,354,352,375,371,337M,356,380,341,369 0
394 341,369,379,376,372,344,343,383,377,351,347,353,355,373,338,370,386,340,350,381,349,357,374,345,382,384,342,339,378,358,385,354,352,375,371,337M,356,380 0
395 339,358,354,352,337M,356,341,344,343,351,347,353,355,338,340,350,349,357,345,342 0
396 378,345,342,375,371,339,358,354,352,337M,356,369,341,376,372,377,344,343,373,351,347,370,353,355,338,374,340,350,349,357 0
397 338,340,350,349,357,345,342,339,358,354,352,337M,356,341,344,343,351,347,353,355 0
398 353,355,393,363,338,390,340,389,350,349,357,391,345,361,342,368,392,339,358,354,352,337M,356,341,395,388,394,360,362,396,344,343,351,347,359 0
399 344,343,351,347,353,355,338,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
400 344,343,351,347,353,355,338,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
402 354,352,337M,356,341,359,393,363,390,344,343,351,347,391,353,355,361,368,392,338,340,350,349,357,345,395,342,388,394,360,362,339,358,396 0
404 342,339,358,354,352,337M,356,341,344,343,351,347,353,355,338,340,350,349,357,345 0
405 340,374,395,350,388,394,349,360,357,362,396,345,378,342,339,375,371,359,358,354,352,337M,356,393,341,369,363,390,376,372,377,391,344,343,361,351,368,392,347,373,353,355,370,338 0
406 355,338,340,395,350,388,394,349,360,357,362,396,345,342,339,359,358,354,352,337M,356,393,341,363,390,391,344,343,361,351,368,392,347,353 0
407 361,351,347,368,385,392,353,380,355,338,340,379,395,350,388,394,349,360,357,362,383,396,345,342,339,359,358,354,352,337M,356,386,393,341,363,381,390,382,384,391,344,343 0
408 370,382,384,344,343,374,351,347,385,353,380,355,378,338,375,371,340,379,350,349,357,383,369,345,342,376,372,339,358,377,354,352,337M,356,386,341,373,381 0
409 337M,356,341,344,343,351,347,353,355,340,350,349,357,345,342,339,358,354,352 0
410 339,358,354,352,337M,356,341,344,343,351,338,353,355,340,350,349,357,345,342 0
412 349,357,345,342,339,358,354,352,337M,356,341,347,344,343,351,338,353,355,340,350 0
413 373,340,350,349,357,370,361,368,345,342,374,339,358,354,352,337M,356,378,341,360,362,375,371,344,343,359,369,351,376,372,338,353,377,363,355 0
414 338,353,377,363,355,373,340,350,349,357,370,361,368,345,342,374,339,358,354,352,337M,356,378,341,360,362,375,371,344,343,359,369,351,376,372 0
415 344,343,351,338,353,355,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
416 341,359,391,392,344,343,363,351,338,353,355,361,395,368,388,394,340,350,396,349,357,345,342,339,360,358,362,393,354,352,337M,356,390 0
417 358,354,352,337M,356,341,344,343,351,338,353,355,340,350,349,357,345,342,339 0
418 345,342,369,339,376,372,358,354,352,377,337M,356,341,373,363,370,344,343,351,374,338,353,355,378,340,375,371,350,349,357 0
419 360,362,393,340,350,349,357,390,345,342,359,391,339,358,354,392,352,389,337M,356,341,363,361,395,368,388,394,344,343,351,396,338,353,355 0
420 355,340,350,349,357,345,342,339,358,354,352,337M,356,341,344,343,351,338,353 0
421 344,343,351,338,353,360,362,393,355,390,340,350,359,391,349,357,345,392,342,339,358,354,352,363,337M,356,341,361,395,368,388,394,396 0
422 344,343,351,338,353,355,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
424 337M,356,341,344,343,351,338,353,355,347,340,350,349,357,345,342,339,358,354,352 0
425 342,339,358,354,352,337M,356,341,344,343,351,338,353,355,347,340,350,349,357,345 0
426 386,349,357,375,371,381,345,342,339,382,384,358,354,376,372,352,337M,356,385,377,341,373,344,343,370,379,351,383,338,353,374,355,378,340,350 0
427 378,340,350,386,349,357,375,371,369,381,345,342,339,382,384,358,354,376,372,380,352,337M,356,385,377,341,373,344,343,370,379,351,383,338,353,374,347,355 0
428 338,353,396,347,355,340,350,360,362,393,349,357,390,345,342,339,359,391,358,354,352,337M,356,392,341,363,344,343,361,395,368,388,394,351 0
429 344,343,351,338,353,355,340,350,349,357,345,342,339,358,354,352,337M,356,341 0
430 341,344,343,351,338,353,355,340,350,349,357,345,342,339,358,354,352,337M,356 0
431 339,363,358,354,352,361,395,337M,356,368,388,394,341,396,344,343,351,360,362,393,338,353,390,355,359,391,350,349,357,392,345,342 0
432 345,342,339,358,354,352,347,337M,356,341,344,343,351,338,353,340,355,350,349,357 0
434 383,350,349,357,363,345,342,361,368,339,386,358,354,352,381,347,337M,356,341,382,384,380,360,362,385,344,343,351,338,359,353,340,355,379 0
441 338,359,353,340,355,383,350,349,357,363,371,345,369,342,361,368,339,358,354,352,381,347,337M,356,372,341,382,384,380,360,362,344,343,351,370 0
1465 344,343,351,374,370,379,338,359,353,340,355,378,395,388,394,375,383,396,350,349,357,386,363,371,345,369,342,361M,376,368,339,393,358,354,377,352,381,390,347,337,356,372,341,385,373,382,384,391,380,360,362,392 0
1529 373,384,391,380,360,362,392,344,343,351,374,370,379,338,359,353,340,355,378,395,388,394,375,396,350,349M,357,386,363,371,345,369,342,361,376,368,339,393,358,354,377,352,381,390,347,337,356,372,341,385 0
1930 354,377,352,381,390,337,356,341,391,362,351,379,338,359,353,340,355,395,388,375,350,349,363,345,369,361M,376,339 0
1934 369,361M,372,339,354,377,373,384,352,381,390,337,356,360,391,344,374,370,362,379,394,338,359,340,355,396,395,350,342,349,363,358,345 0
1936 350,349,376,363,345,369,361M,339,341,377,373,384,352,381,390,337,356,360,391,378,374,370,362,353,379,388,394,338,359,386,375,396,395 0
1937 382,396,342,395,347,358,385,350,349,376,372,380,363,392,345,354,369,343,361M,339,341,377,373,384,352,344,381,390,337,356,351,360,391,378,374,370,362,357,353,371,340,355,379,368,388,394,338,359,386,393,375 0