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

Query time 0.01281

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "222.08"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "38.03"
      },
      "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": 38,
            "filtered": "41.33",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,382,418,400,424,381,1529,401,1465,1935,428,415,391,406,439,390,393,394,396,397,398,399,422,434,383,412,419,430,431,432,429,384,1934,395,420,385,405,410,413,417,1937,414,425,407,389,402,388,426,409,404,387,386,416,441,322))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "7.61",
              "prefix_cost": "138.42",
              "data_read_per_join": "608"
            },
            "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": 38,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "38.03",
              "eval_cost": "7.61",
              "prefix_cost": "184.06",
              "data_read_per_join": "608"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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