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 = 39 
WHERE 
  cscart_products_categories.product_id IN (
    8408, 8409, 10177, 8405, 8406, 9943, 
    16031, 8407, 8649, 36024, 36025, 26577, 
    12085, 26543, 26539, 31010, 39503, 
    12086, 40547, 40112, 40580, 12088, 
    40714, 33996, 12087, 26542, 36036, 
    33791, 40836, 40232, 40208, 40469, 
    40616, 26537, 40738, 36041, 40374, 
    40088, 40787, 40679, 40516, 40350, 
    34008, 40812, 40762, 40160, 40326, 
    40422, 40136, 40302
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00203

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "120.61"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 94,
            "rows_produced_per_join": 94,
            "filtered": "100.00",
            "index_condition": "(`cscartdb`.`cscart_products_categories`.`product_id` in (8408,8409,10177,8405,8406,9943,16031,8407,8649,36024,36025,26577,12085,26543,26539,31010,39503,12086,40547,40112,40580,12088,40714,33996,12087,26542,36036,33791,40836,40232,40208,40469,40616,26537,40738,36041,40374,40088,40787,40679,40516,40350,34008,40812,40762,40160,40326,40422,40136,40302))",
            "cost_info": {
              "read_cost": "45.41",
              "eval_cost": "9.40",
              "prefix_cost": "54.81",
              "data_read_per_join": "1K"
            },
            "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",
              "cscartdb.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 94,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "23.50",
              "eval_cost": "9.40",
              "prefix_cost": "87.71",
              "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": [
              "cscartdb.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "23.50",
              "eval_cost": "0.47",
              "prefix_cost": "120.61",
              "data_read_per_join": "15K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`cscartdb`.`cscart_categories`.`storefront_id` in (0,1)) and ((`cscartdb`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`cscartdb`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`cscartdb`.`cscart_categories`.`usergroup_ids`))) and (`cscartdb`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
8405 212,39M 0
8406 213,39M 0
8407 214,39M 0
8408 215,39M 0
8409 217,39M 0
8649 378,62M
9943 822,61M
10177 211,62M
12085 822,61M
12086 822,61M
12087 822,61M
12088 822,61M
16031 595,61M
26537 822,39M 0
26539 822,39M 0
26542 822,39M 0
26543 822,39M 0
26577 822,39M 0
31010 936,39M 0
33791 982,39M 0
33996 982,39M 0
34008 982,39M 0
36024 1025,39M 0
36025 1025,39M 0
36036 1025,39M 0
36041 1025,61M
39503 1189,61M
40088 1189,61M
40112 1189,61M
40136 1189,61M
40160 1189,61M
40208 1189,61M
40232 1189,61M
40302 1189,61M
40326 1189,61M
40350 1189,61M
40374 1189,61M
40422 1189,61M
40469 1189,61M
40516 1189,61M
40547 1189,61M
40580 1189,61M
40616 1189,61M
40679 1189,61M
40714 1189,61M
40738 1189,61M
40762 1189,61M
40787 1189,61M
40812 1189,61M
40836 1189,61M