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 = 7223 
WHERE 
  cscart_products_categories.product_id IN (
    84640, 84641, 84508, 84509, 84574, 84575, 
    84638, 84639, 84636, 84637, 84506, 
    84507, 84572, 84573, 84661, 84662, 
    84504, 84505, 84570, 84571, 84634, 
    84635, 84310, 84311, 84502, 84503, 
    84568, 84569, 84529, 84530, 84595, 
    84596, 84665, 84666, 84533, 84534, 
    84599, 84600, 84306, 84307, 84308, 
    84309, 84519, 84331, 84332, 84304, 
    84305, 84632, 84633, 84681, 84682, 
    84685, 84686, 84679, 84680, 84683, 
    84684, 84622, 84623, 84500, 84501, 
    84566, 84567, 84549, 84550, 84553, 
    84554, 84615, 84616, 84619, 84620, 
    84652, 84653, 84547, 84548, 84551, 
    84552, 84613, 84614, 84617, 84618, 
    84335, 84336, 84490, 84491, 84556, 
    84557, 84520, 84521, 84586, 84587, 
    84663, 84664, 84302, 84303, 84351
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00212

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "54.77"
    },
    "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": 96,
            "rows_produced_per_join": 96,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "9.89",
              "eval_cost": "9.60",
              "prefix_cost": "19.49",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (84640,84641,84508,84509,84574,84575,84638,84639,84636,84637,84506,84507,84572,84573,84661,84662,84504,84505,84570,84571,84634,84635,84310,84311,84502,84503,84568,84569,84529,84530,84595,84596,84665,84666,84533,84534,84599,84600,84306,84307,84308,84309,84519,84331,84332,84304,84305,84632,84633,84681,84682,84685,84686,84679,84680,84683,84684,84622,84623,84500,84501,84566,84567,84549,84550,84553,84554,84615,84616,84619,84620,84652,84653,84547,84548,84551,84552,84613,84614,84617,84618,84335,84336,84490,84491,84556,84557,84520,84521,84586,84587,84663,84664,84302,84303,84351))"
          }
        },
        {
          "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": [
              "nuie_scalesta_net.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "24.00",
              "eval_cost": "0.48",
              "prefix_cost": "53.09",
              "data_read_per_join": "12K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`nuie_scalesta_net`.`cscart_categories`.`storefront_id` in (0,1)) and ((`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`))) and (`nuie_scalesta_net`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "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",
              "nuie_scalesta_net.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 4,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.20",
              "eval_cost": "0.48",
              "prefix_cost": "54.77",
              "data_read_per_join": "76"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
84302 7223M 0
84303 7223M 0
84304 7223M 0
84305 7223M 0
84306 7223M 0
84307 7223M 0
84308 7223M 0
84309 7223M 0
84310 7223M 0
84311 7223M 0
84331 7223M 0
84332 7223M 0
84335 7223M 0
84336 7223M 0
84351 7223M 0
84490 7223M 0
84491 7223M 0
84500 7223M 0
84501 7223M 0
84502 7223M 0
84503 7223M 0
84504 7223M 0
84505 7223M 0
84506 7223M 0
84507 7223M 0
84508 7223M 0
84509 7223M 0
84519 7223M 0
84520 7223M 0
84521 7223M 0
84529 7223M 0
84530 7223M 0
84533 7223M 0
84534 7223M 0
84547 7223M 0
84548 7223M 0
84549 7223M 0
84550 7223M 0
84551 7223M 0
84552 7223M 0
84553 7223M 0
84554 7223M 0
84556 7223M 0
84557 7223M 0
84566 7223M 0
84567 7223M 0
84568 7223M 0
84569 7223M 0
84570 7223M 0
84571 7223M 0
84572 7223M 0
84573 7223M 0
84574 7223M 0
84575 7223M 0
84586 7223M 0
84587 7223M 0
84595 7223M 0
84596 7223M 0
84599 7223M 0
84600 7223M 0
84613 7223M 0
84614 7223M 0
84615 7223M 0
84616 7223M 0
84617 7223M 0
84618 7223M 0
84619 7223M 0
84620 7223M 0
84622 7223M 0
84623 7223M 0
84632 7223M 0
84633 7223M 0
84634 7223M 0
84635 7223M 0
84636 7223M 0
84637 7223M 0
84638 7223M 0
84639 7223M 0
84640 7223M 0
84641 7223M 0
84652 7223M 0
84653 7223M 0
84661 7223M 0
84662 7223M 0
84663 7223M 0
84664 7223M 0
84665 7223M 0
84666 7223M 0
84679 7223M 0
84680 7223M 0
84681 7223M 0
84682 7223M 0
84683 7223M 0
84684 7223M 0
84685 7223M 0
84686 7223M 0