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 = 266 
WHERE 
  cscart_products_categories.product_id IN (
    387039, 339692, 339737, 339535, 339534, 
    339573, 339496, 339617, 339620, 339621, 
    339742, 339611, 339533, 339710, 81689, 
    339587, 339683, 339444, 170248, 387094, 
    339722, 387042, 339570, 339610, 81674, 
    339584, 339771, 170250, 435270, 339638, 
    159865, 339625, 339706, 339529, 339751, 
    387037, 339736, 173787, 339618, 254333, 
    265275, 387092, 339569, 339581, 339615, 
    159861, 339770, 387040, 339705, 339608, 
    205885, 339619, 254332, 258305, 339783, 
    339693, 391684, 339732, 339779, 339759, 
    339607, 170249, 339572, 159863, 254325, 
    159864, 339775, 170247, 339476, 339589, 
    339652, 339571, 254327, 339778, 391687, 
    387089, 170216, 387056, 173789, 391688, 
    387096, 387093, 170251, 387041, 173763, 
    339738, 339456, 339686, 339550, 391689, 
    387098, 339780, 339739, 387045, 339644, 
    339747, 339586, 339630, 391800, 387044
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00293

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "297.96"
    },
    "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": 106,
            "rows_produced_per_join": 106,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "22.36",
              "eval_cost": "21.20",
              "prefix_cost": "43.56",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`webmarco`.`cscart_products_categories`.`product_id` in (387039,339692,339737,339535,339534,339573,339496,339617,339620,339621,339742,339611,339533,339710,81689,339587,339683,339444,170248,387094,339722,387042,339570,339610,81674,339584,339771,170250,435270,339638,159865,339625,339706,339529,339751,387037,339736,173787,339618,254333,265275,387092,339569,339581,339615,159861,339770,387040,339705,339608,205885,339619,254332,258305,339783,339693,391684,339732,339779,339759,339607,170249,339572,159863,254325,159864,339775,170247,339476,339589,339652,339571,254327,339778,391687,387089,170216,387056,173789,391688,387096,387093,170251,387041,173763,339738,339456,339686,339550,391689,387098,339780,339739,387045,339644,339747,339586,339630,391800,387044))"
          }
        },
        {
          "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": 106,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "106.00",
              "eval_cost": "21.20",
              "prefix_cost": "170.76",
              "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": "106.00",
              "eval_cost": "1.06",
              "prefix_cost": "297.96",
              "data_read_per_join": "31K"
            },
            "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
81674 2404M
81689 2404M
159861 9290M
159863 9290M
159864 9290M
159865 9290M
170216 932M
170247 8944M
170248 8944M
170249 945M
170250 935M
170251 932M
173763 396M
173787 396M
173789 396M
205885 9623M
254325 2599M
254327 2604M
254332 1936M
254333 2387M
258305 2578M
265275 2374M
339444 9940M
339456 9940M
339476 9940M
339496 9942M
339529 9942M
339533 9942M
339534 9942M
339535 9942M
339550 9940M
339569 9941M
339570 9941M
339571 9941M
339572 9941M
339573 9941M
339581 9941M
339584 9941M
339586 9941M
339587 9941M
339589 9941M
339607 9941M
339608 9941M
339610 9941M
339611 9941M
339615 9941M
339617 9941M
339618 9941M
339619 9941M
339620 9941M
339621 9941M
339625 9941M
339630 395M
339638 9941M
339644 395M
339652 395M
339683 9941M
339686 9941M
339692 9941M
339693 9941M
339705 9941M
339706 9941M
339710 9941M
339722 395M
339732 9941M
339736 9941M
339737 9941M
339738 9941M
339739 9941M
339742 9941M
339747 395M
339751 395M
339759 395M
339770 9941M
339771 9941M
339775 9941M
339778 9941M
339779 9941M
339780 9941M
339783 395M
387037 10425M
387039 10425M
387040 10425M
387041 10425M
387042 10425M
387044 1505M
387045 1518,10425,10426M
387056 10425,1505M
387089 10425M
387092 10425M
387093 10425M
387094 10425M
387096 1505M
387098 1505,10426,1518M
391684 394M
391687 9936M
391688 9936M
391689 9936M
391800 266M 0
435270 9401,9276M