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 = 265 
WHERE 
  cscart_products_categories.product_id IN (
    3863, 3148, 6718, 6722, 3144, 3147, 3096, 
    339, 3104, 3107, 6682, 6678, 104, 105, 
    106, 107, 108, 109, 110, 4013, 4014, 
    4015, 4016, 4017, 4018, 4019, 3105, 
    6677, 6686, 64, 118, 224, 225, 285, 3975, 
    4027, 4108, 4109, 4170, 4223, 203, 204, 
    205, 206, 207, 208, 209, 4087, 4088, 
    4089, 4090, 4091, 4092, 4093, 3122, 
    6675, 6696, 6703, 3118, 3111, 3124, 
    3112, 324, 3419, 6704, 3418, 6709, 6946, 
    4177, 6945, 338, 331, 6705, 3932, 3134, 
    3116, 3126, 6673, 6679, 6691, 3155, 
    3131, 310, 303, 3939, 317, 3132, 3143, 
    3130, 3129, 3121, 3128, 6681, 6695, 
    3098, 3115
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00278

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.48"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.61"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 1,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "4.54",
              "eval_cost": "0.16",
              "prefix_cost": "4.70",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`gaseus`.`cscart_categories`.`storefront_id` in (0,1)) and ((`gaseus`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`gaseus`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`gaseus`.`cscart_categories`.`usergroup_ids`))) and (`gaseus`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "gaseus.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 110,
            "rows_produced_per_join": 1,
            "filtered": "0.92",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (3863,3148,6718,6722,3144,3147,3096,339,3104,3107,6682,6678,104,105,106,107,108,109,110,4013,4014,4015,4016,4017,4018,4019,3105,6677,6686,64,118,224,225,285,3975,4027,4108,4109,4170,4223,203,204,205,206,207,208,209,4087,4088,4089,4090,4091,4092,4093,3122,6675,6696,6703,3118,3111,3124,3112,324,3419,6704,3418,6709,6946,4177,6945,338,331,6705,3932,3134,3116,3126,6673,6679,6691,3155,3131,310,303,3939,317,3132,3143,3130,3129,3121,3128,6681,6695,3098,3115))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.16",
              "prefix_cost": "66.30",
              "data_read_per_join": "25"
            },
            "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",
              "gaseus.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.40",
              "eval_cost": "0.16",
              "prefix_cost": "66.87",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
64 273M
104 273M
105 273M
106 273M
107 273M
108 273M
109 273M
110 273M
118 273M
203 273M
204 273M
205 273M
206 273M
207 273M
208 273M
209 273M
224 273M
225 273M
285 273M
303 273M
310 273M
317 273M
324 273M
331 273M
338 273M
339 273M
3096 273M
3098 273M
3104 273M
3105 273M
3107 273M
3111 273M
3112 273M
3115 273M
3116 273M
3118 273M
3121 273M
3122 273M
3124 273M
3126 273M
3128 273M
3129 273M
3130 273M
3131 273M
3132 273M
3134 273M
3143 273M
3144 273M
3147 273M
3148 273M
3155 273M
3418 288M
3419 288M
3863 273M
3932 273M
3939 273M
3975 273M
4013 273M
4014 273M
4015 273M
4016 273M
4017 273M
4018 273M
4019 273M
4027 273M
4087 273M
4088 273M
4089 273M
4090 273M
4091 273M
4092 273M
4093 273M
4108 273M
4109 273M
4170 273M
4177 273M
4223 273M
6673 273M
6675 273M
6677 273M
6678 273M
6679 273M
6681 273M
6682 273M
6686 273M
6691 273M
6695 273M
6696 273M
6703 273M
6704 273M
6705 273M
6709 273M
6718 273M
6722 273M
6945 282,267,288M
6946 288M,267,282