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 = 9 
WHERE 
  cscart_products_categories.product_id IN (
    36, 1046, 3332, 40, 1206, 1734, 5800, 
    5799, 7190, 7189, 5032, 5033, 6645, 
    6644, 4352, 5391, 5392, 6767, 6766, 
    4799, 4723, 4724, 7774, 7757, 3356, 
    5271, 5270, 5269, 5268, 4130, 4129, 
    4128, 4126, 4123, 4125, 4213, 4127, 
    4131, 4124, 1413, 1412, 1411, 1908, 
    1909, 4955, 4954, 4957, 4958, 7676, 
    7683, 7298, 7297, 5968, 2639, 5113, 
    7295, 7772, 7771, 7294, 7296, 2640, 
    7768, 7759, 7867, 7758, 7868, 2641, 
    7317, 7320, 7321, 2642, 5112, 3141, 
    7318, 3142, 2643, 3143, 7760, 7761, 
    7762, 3144, 5414, 5411, 5413, 5412, 
    5415, 4321, 4320, 4323, 4322, 4324, 
    4325, 4337, 4338, 4340, 4339
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00347

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "296.24"
    },
    "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": 333,
            "rows_produced_per_join": 333,
            "filtered": "100.00",
            "index_condition": "(`dbggbern`.`cscart_products_categories`.`product_id` in (36,1046,3332,40,1206,1734,5800,5799,7190,7189,5032,5033,6645,6644,4352,5391,5392,6767,6766,4799,4723,4724,7774,7757,3356,5271,5270,5269,5268,4130,4129,4128,4126,4123,4125,4213,4127,4131,4124,1413,1412,1411,1908,1909,4955,4954,4957,4958,7676,7683,7298,7297,5968,2639,5113,7295,7772,7771,7294,7296,2640,7768,7759,7867,7758,7868,2641,7317,7320,7321,2642,5112,3141,7318,3142,2643,3143,7760,7761,7762,3144,5414,5411,5413,5412,5415,4321,4320,4323,4322,4324,4325,4337,4338,4340,4339))",
            "cost_info": {
              "read_cost": "140.56",
              "eval_cost": "33.30",
              "prefix_cost": "173.86",
              "data_read_per_join": "5K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "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": [
              "dbggbern.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 16,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "83.25",
              "eval_cost": "1.67",
              "prefix_cost": "290.41",
              "data_read_per_join": "66K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`dbggbern`.`cscart_categories`.`storefront_id` in (0,1)) and ((`dbggbern`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`dbggbern`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`dbggbern`.`cscart_categories`.`usergroup_ids`))) and (`dbggbern`.`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",
              "dbggbern.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 16,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "4.16",
              "eval_cost": "1.67",
              "prefix_cost": "296.24",
              "data_read_per_join": "266"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
36 23,9M 0
40 23,9M 0
1046 23,9M 0
1206 23,9M 0
1411 9,67,7M 0
1412 9,7M 0
1413 9,7M 0
1734 23,9M 0
1908 67,9,7M 0
1909 67,9,7M 0
2639 9,67,7M 0
2640 67,9,7M 0
2641 7,67,9M 0
2642 7,67,9M 0
2643 67,7,9M 0
3141 7,67,9M 0
3142 7,67,9M 0
3143 7,67,9M 0
3144 7,67,9M 0
3332 23,9M 0
3356 9,25,7M 0
4123 67,9M 0
4124 67,9M 0
4125 67,9M 0
4126 67,9M 0
4127 67,9M 0
4128 67,9M 0
4129 67,9M 0
4130 67,9M 0
4131 67,9M 0
4213 9,67,7M 0
4320 67,444,7,9,400M 0
4321 9,444,7,67,400M 0
4322 67,444,7,9,400M 0
4323 67,444,7,9,400M 0
4324 67,444,7,9,400M 0
4325 67,444,7,9,400M 0
4337 67,444,7,9,400M 0
4338 67,444,7,9,400M 0
4339 67,444,7,9,400M 0
4340 67,444,7,9,400M 0
4352 327,7,9,325M 0
4723 9,25,7M 0
4724 9,25,7M 0
4799 9,25,7M 0
4954 67,9M 0
4955 67,9M 0
4957 67,9M 0
4958 9,67M 0
5032 7,454,276,9,325M 0
5033 7,454,276,9,325M 0
5112 9,67,7M 0
5113 67,9,7M 0
5268 664,349,9,67,8,7M 0
5269 9,67,8,349,664,7M 0
5270 349,9,67,8,664,7M 0
5271 349,39,9,67,8,664,7M 0
5391 495,9,331,329,7,325M 0
5392 495,9,331,329,7,325M 0
5411 9,67,7M 0
5412 9,67,7M 0
5413 9,67,7M 0
5414 9,67,7M 0
5415 9,67,7M 0
5799 7,331,9,329,521,325M 0
5800 7,331,9,329,521,325M 0
5968 67,9,7M 0
6644 331,582,7,9,325M 0
6645 331,582,7,9,325M 0
6766 9,7,8,182,349,39,29M 0
6767 182,7,349,8,9,29M 0
7189 641,9,7,331,325M 0
7190 641,9,7,331,325M 0
7294 67,9,7M 0
7295 67,9,7M 0
7296 67,9,7M 0
7297 67,9,7M 0
7298 67,9,7M 0
7317 7,67,9M 0
7318 7,67,9M 0
7320 67,7,9M 0
7321 67,7,9M 0
7676 590,1,9,67,7M 0
7683 67,9,590,1,7M 0
7757 9,25,7M 0
7758 67,9,7M 0
7759 67,9,7M 0
7760 7,9,67M 0
7761 9,67,7M 0
7762 9M 0
7768 67,9,7M 0
7771 67,9,7M 0
7772 67,9,7M 0
7774 9,25,7M 0
7867 67,9,7M 0
7868 67,9,7M 0