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.storefront_id IN (0, 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 = 2 
WHERE 
  cscart_products_categories.product_id IN (
    51480, 51479, 51494, 51495, 132, 112, 
    3, 78, 2, 77, 87, 66, 22421, 22424, 22290, 
    50981, 50982, 133, 45, 143, 50983, 51416, 
    51043, 51421, 51471, 51413, 51057, 
    51472, 51547, 51470, 51500, 51412, 
    51529, 51459, 51457, 51460, 51501, 
    51530, 51464, 51051, 51053, 51551, 
    51478, 51469, 51510, 51486, 51531, 
    51467, 51047, 51461, 51044, 51475, 
    51477, 51473, 51437, 51540, 51048, 
    51525, 51458, 51463, 51516, 51532, 
    51545, 51492, 51514, 51538, 51539, 
    51468, 51476, 51491, 51513, 51474, 
    51503, 51520, 51541, 51462, 51502, 
    51522, 51499, 51465, 51509, 51515, 
    51466, 51485, 51518, 51550, 51519, 
    51524, 51528, 51508, 51527, 51543, 
    51482, 51504, 51542, 51512, 51493, 
    51511, 51505, 51046, 51439, 51544, 
    51054, 51546, 51548, 51438, 51535
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00358

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "165.36"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "20.16"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 383,
            "rows_produced_per_join": 15,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "40.09",
              "eval_cost": "1.53",
              "prefix_cost": "41.62",
              "data_read_per_join": "81K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`test_uchur_k`.`cscart_categories`.`storefront_id` in (0,1)) and ((`test_uchur_k`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`test_uchur_k`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`test_uchur_k`.`cscart_categories`.`usergroup_ids`))) and (`test_uchur_k`.`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": [
              "test_uchur_k.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 18,
            "rows_produced_per_join": 20,
            "filtered": "7.31",
            "index_condition": "(`test_uchur_k`.`cscart_products_categories`.`product_id` in (51480,51479,51494,51495,132,112,3,78,2,77,87,66,22421,22424,22290,50981,50982,133,45,143,50983,51416,51043,51421,51471,51413,51057,51472,51547,51470,51500,51412,51529,51459,51457,51460,51501,51530,51464,51051,51053,51551,51478,51469,51510,51486,51531,51467,51047,51461,51044,51475,51477,51473,51437,51540,51048,51525,51458,51463,51516,51532,51545,51492,51514,51538,51539,51468,51476,51491,51513,51474,51503,51520,51541,51462,51502,51522,51499,51465,51509,51515,51466,51485,51518,51550,51519,51524,51528,51508,51527,51543,51482,51504,51542,51512,51493,51511,51505,51046,51439,51544,51054,51546,51548,51438,51535))",
            "cost_info": {
              "read_cost": "68.94",
              "eval_cost": "2.02",
              "prefix_cost": "138.14",
              "data_read_per_join": "322"
            },
            "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",
              "test_uchur_k.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 20,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "5.04",
              "eval_cost": "2.02",
              "prefix_cost": "145.19",
              "data_read_per_join": "322"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
2 4,40M,42
3 4,40M,42
45 21M,45
66 4,40M,42
77 21,40M
78 21,40M
87 21,40M
112 21,40M,44
132 35,40M,42
133 4,40M,42
143 39M,45
22290 133M
22421 40,133M
22424 40,133M
50981 133M
50982 133M
50983 40,133M
51043 231M
51044 231M
51046 231M
51047 231M
51048 231M
51051 231M
51053 231M
51054 133M
51057 231M
51412 133M
51413 133M
51416 133M
51421 133M
51437 395M
51438 395M
51439 395M
51457 4M
51458 4M
51459 4M
51460 4M
51461 4M
51462 4M
51463 4M
51464 4M
51465 4M
51466 4M
51467 4M
51468 4M
51469 3M
51470 3M
51471 117M
51472 117M
51473 117M
51474 117M
51475 117M
51476 117M
51477 3M
51478 117M
51479 4M,40,42
51480 4M,40,42
51482 117M
51485 4M
51486 4M
51491 117M
51492 117M
51493 3M
51494 40,42,204M
51495 40M,42,204
51499 83M
51500 83M
51501 158M
51502 158M
51503 83M
51504 83M
51505 158M
51508 83M
51509 193M
51510 260M
51511 191M
51512 258M
51513 258M
51514 258M
51515 258M
51516 258M
51518 35M
51519 78M
51520 78M
51522 78M
51524 279M
51525 279M
51527 205M
51528 205M
51529 205M
51530 83M
51531 260M
51532 190M
51535 158M
51538 193M
51539 193M
51540 237M
51541 237M
51542 237M
51543 237M
51544 79M
51545 79M
51546 79M
51547 81M
51548 81M
51550 79M
51551 237M