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 = 7165 
WHERE 
  cscart_products_categories.product_id IN (
    94311, 94312, 94313, 94314, 94315, 94316, 
    94317, 94318, 94319, 94320, 94321, 
    94322, 94323, 94324, 94325, 94326, 
    94327, 94328, 94329, 94330, 94331, 
    94332, 94381, 94838, 94849, 94958, 
    94965, 94966, 94967, 94968, 94969, 
    94970, 94971, 94972, 94973, 94974, 
    94975, 94976, 94977, 94978, 94979, 
    94980, 94981, 94982, 94983, 94984, 
    94985, 94986, 94987, 94988, 94989, 
    94990, 94991, 94992, 94993, 94994, 
    94995, 94996, 94997, 94998, 94999, 
    95000, 95001, 95002, 95003, 95004, 
    95005, 95006, 95007, 95008, 95009, 
    95010, 95011, 95012, 95013, 95014, 
    95015, 95016, 95017, 95018, 95019, 
    95020, 95021, 95022, 95023, 95024, 
    95025, 95026, 95027, 95028, 95029, 
    95030, 95031, 95032, 95033, 95034
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01662

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "89.39"
    },
    "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": 99,
            "rows_produced_per_join": 99,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "10.20",
              "eval_cost": "9.90",
              "prefix_cost": "20.10",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (94311,94312,94313,94314,94315,94316,94317,94318,94319,94320,94321,94322,94323,94324,94325,94326,94327,94328,94329,94330,94331,94332,94381,94838,94849,94958,94965,94966,94967,94968,94969,94970,94971,94972,94973,94974,94975,94976,94977,94978,94979,94980,94981,94982,94983,94984,94985,94986,94987,94988,94989,94990,94991,94992,94993,94994,94995,94996,94997,94998,94999,95000,95001,95002,95003,95004,95005,95006,95007,95008,95009,95010,95011,95012,95013,95014,95015,95016,95017,95018,95019,95020,95021,95022,95023,95024,95025,95026,95027,95028,95029,95030,95031,95032,95033,95034))"
          }
        },
        {
          "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": 99,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "24.75",
              "eval_cost": "9.90",
              "prefix_cost": "54.75",
              "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": [
              "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.75",
              "eval_cost": "0.50",
              "prefix_cost": "89.40",
              "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')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
94311 7166M
94312 7166M
94313 7166M
94314 7166M
94315 7166M
94316 7166M
94317 7166M
94318 7166M
94319 7166M
94320 7166M
94321 7166M
94322 7166M
94323 7166M
94324 7166M
94325 7166M
94326 7166M
94327 7166M
94328 7166M
94329 7166M
94330 7166M
94331 7166M
94332 7166M
94381 7226,7225M
94838 7176M
94849 7168M
94958 7283,7183,7167M
94965 7172M
94966 7172M
94967 7172M
94968 7172M
94969 7172M
94970 7172M
94971 7172M
94972 7172M
94973 7172M
94974 7172M
94975 7172M
94976 7172M
94977 7172M
94978 7172M
94979 7172M
94980 7172M
94981 7172M
94982 7172M
94983 7169M
94984 7169M
94985 7169M
94986 7169M
94987 7169M
94988 7169M
94989 7169M
94990 7169M
94991 7169M
94992 7175M
94993 7175M
94994 7175M
94995 7175M
94996 7175M
94997 7175M
94998 7175M
94999 7175M
95000 7175M
95001 7175M
95002 7175M
95003 7175M
95004 7176M
95005 7176M
95006 7176M
95007 7176M
95008 7176M
95009 7176M
95010 7177M
95011 7177M
95012 7177M
95013 7177M
95014 7177M
95015 7177M
95016 7177M
95017 7177M
95018 7177M
95019 7177M
95020 7177M
95021 7177M
95022 7177M
95023 7177M
95024 7177M
95025 7177M
95026 7177M
95027 7177M
95028 7177M
95029 7177M
95030 7177M
95031 7177M
95032 7177M
95033 7177M
95034 7166M