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 = 394 
WHERE 
  cscart_products_categories.product_id IN (
    339776, 339474, 339552, 339649, 339743, 
    339756, 339647, 339665, 339470, 339773, 
    339577, 339848, 339703, 339749, 339669, 
    339455, 339666, 339789, 339651, 339565, 
    339544, 339626, 339670, 339543, 339646, 
    339824, 339833, 339834, 339575, 339784, 
    339698, 339830, 339631, 339628, 339662, 
    339767, 339557, 339567, 339549, 339595, 
    339823, 339673, 339853, 339658, 339717, 
    339763, 339852, 339542, 339818, 339653, 
    339487, 339822, 339472, 339613, 339682, 
    339480, 339555, 339639, 339560, 339579, 
    339680, 339559, 339788, 339850, 339854, 
    339815, 339772, 339561, 339785, 339766, 
    339475, 339688, 339566, 339661, 339558, 
    339819, 339585, 339837, 339563, 339640, 
    339568, 339790, 339578, 339634, 339598, 
    339629, 339672, 339546, 339844, 339641, 
    339832, 339840, 339624, 339627, 339687, 
    339842, 339612, 339827, 339642, 339800
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00366

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "281.15"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 100,
            "rows_produced_per_join": 100,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "21.15",
              "eval_cost": "20.00",
              "prefix_cost": "41.15",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`webmarco`.`cscart_products_categories`.`product_id` in (339776,339474,339552,339649,339743,339756,339647,339665,339470,339773,339577,339848,339703,339749,339669,339455,339666,339789,339651,339565,339544,339626,339670,339543,339646,339824,339833,339834,339575,339784,339698,339830,339631,339628,339662,339767,339557,339567,339549,339595,339823,339673,339853,339658,339717,339763,339852,339542,339818,339653,339487,339822,339472,339613,339682,339480,339555,339639,339560,339579,339680,339559,339788,339850,339854,339815,339772,339561,339785,339766,339475,339688,339566,339661,339558,339819,339585,339837,339563,339640,339568,339790,339578,339634,339598,339629,339672,339546,339844,339641,339832,339840,339624,339627,339687,339842,339612,339827,339642,339800))"
          }
        },
        {
          "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",
              "webmarco.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 100,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "100.00",
              "eval_cost": "20.00",
              "prefix_cost": "161.15",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "webmarco.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "100.00",
              "eval_cost": "1.00",
              "prefix_cost": "281.15",
              "data_read_per_join": "29K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`webmarco`.`cscart_categories`.`storefront_id` in (0,1)) and ((`webmarco`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`webmarco`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`webmarco`.`cscart_categories`.`usergroup_ids`)) and (`webmarco`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
339455 9940M
339470 9940M
339472 9940M
339474 9940M
339475 9940M
339480 9940M
339487 9940M
339542 9940M
339543 9940M
339544 9940M
339546 9940M
339549 9940M
339552 395M
339555 395M
339557 395M
339558 395M
339559 395M
339560 395M
339561 395M
339563 395M
339565 395M
339566 395M
339567 395M
339568 395M
339575 9941M
339577 395M
339578 395M
339579 395M
339585 395M
339595 395M
339598 395M
339612 395M
339613 395M
339624 395M
339626 395M
339627 395M
339628 395M
339629 395M
339631 395M
339634 395M
339639 395M
339640 395M
339641 395M
339642 395M
339646 395M
339647 395M
339649 395M
339651 395M
339653 395M
339658 395M
339661 395M
339662 395M
339665 395M
339666 395M
339669 395M
339670 395M
339672 395M
339673 395M
339680 395M
339682 395M
339687 9940M
339688 9940M
339698 9940M
339703 395M
339717 395M
339743 395M
339749 395M
339756 395M
339763 395M
339766 395M
339767 395M
339772 395M
339773 395M
339776 9941M
339784 9943M
339785 9943M
339788 9943M
339789 9943M
339790 9943M
339800 9943M
339815 395M
339818 395M
339819 395M
339822 395M
339823 395M
339824 395M
339827 395M
339830 395M
339832 395M
339833 395M
339834 395M
339837 395M
339840 395M
339842 395M
339844 395M
339848 395M
339850 395M
339852 395M
339853 395M
339854 395M