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 = 7 
WHERE 
  cscart_products_categories.product_id IN (
    104, 2593, 2711, 2710, 2693, 2709, 2976, 
    2735, 2694, 3187, 2990, 4735, 2991, 
    2989, 863, 1478, 1479, 781, 862, 3175, 
    7926, 1480, 1482, 2446, 1481, 6430, 
    6431, 7254, 7255, 4050, 4051, 4602, 
    4049, 4034, 4048, 4419, 4601, 4422, 
    4418, 4421, 4420, 4423, 4600, 5961, 
    5960, 5958, 5959, 5213, 621, 860, 619, 
    861, 5653, 59, 122, 5662, 61, 2992, 5663, 
    123, 63, 58, 121, 124, 62, 785, 784, 786, 
    782, 787, 783, 1511, 3586, 1924, 1773, 
    3665, 3666, 4625, 6421, 7262, 5971, 
    1727, 5957, 6422, 6423, 6424, 7252, 
    7253, 7250, 6717, 6719, 6718, 7251, 
    4614, 3869, 1772
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00390

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "273.35"
    },
    "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": 305,
            "rows_produced_per_join": 305,
            "filtered": "100.00",
            "index_condition": "(`dbggbern`.`cscart_products_categories`.`product_id` in (104,2593,2711,2710,2693,2709,2976,2735,2694,3187,2990,4735,2991,2989,863,1478,1479,781,862,3175,7926,1480,1482,2446,1481,6430,6431,7254,7255,4050,4051,4602,4049,4034,4048,4419,4601,4422,4418,4421,4420,4423,4600,5961,5960,5958,5959,5213,621,860,619,861,5653,59,122,5662,61,2992,5663,123,63,58,121,124,62,785,784,786,782,787,783,1511,3586,1924,1773,3665,3666,4625,6421,7262,5971,1727,5957,6422,6423,6424,7252,7253,7250,6717,6719,6718,7251,4614,3869,1772))",
            "cost_info": {
              "read_cost": "130.76",
              "eval_cost": "30.50",
              "prefix_cost": "161.26",
              "data_read_per_join": "4K"
            },
            "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": 15,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "76.25",
              "eval_cost": "1.53",
              "prefix_cost": "268.01",
              "data_read_per_join": "61K"
            },
            "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": 15,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "3.81",
              "eval_cost": "1.53",
              "prefix_cost": "273.35",
              "data_read_per_join": "244"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
58 24,182,8M
59 182,24,8M
61 182,24,8M
62 182,24,8M
63 182,24,8M
104 24,28M
121 8,24,182,7M 0
122 8,24,182,7M 0
123 8,24,182,7M 0
124 182,24,8M
619 183,7,8M 0
621 183,7,8M 0
781 24,16,7M 0
782 24,39,7M 0
783 39,7M 0
784 39,7M 0
785 39,7M 0
786 39,7M 0
787 39,7M 0
860 7,183,8M 0
861 7,183,8M 0
862 16,24M
863 24,16,7M 0
1478 16M
1479 16M
1480 24,16,7M 0
1481 24,16,7M 0
1482 24,16,7M 0
1511 39,7M 0
1727 276,167,7M 0
1772 184,7M 0
1773 24,9,7M 0
1924 24,7M 0
2446 24,16,7M 0
2593 24,16,7M 0
2693 16,24,7M 0
2694 24,16,7M 0
2709 24,16,7M 0
2710 24,16,7M 0
2711 16,24,7M 0
2735 24,16,7M 0
2976 24,16,7M 0
2989 24,16,7M 0
2990 24,7,16M 0
2991 16,24M
2992 182,24,184,8M
3175 24,16,39,7M 0
3187 24,16,7M 0
3586 39,24,7M 0
3665 9,24,7M 0
3666 24,9,7M 0
3869 7,16,24M 0
4034 39,9,24,7M 0
4048 7,9,39,24M 0
4049 39,9,24,7M 0
4050 7,9,39,24M 0
4051 39,9,24,7M 0
4418 24,9M
4419 24,9M
4420 24,9M
4421 9,24,7M 0
4422 24,9M
4423 24,9M
4600 24,9M
4601 24,9M
4602 39,9,24,7M 0
4614 16,24,7M 0
4625 24,9,7M 0
4735 16,24,7M 0
5213 8,184,183,24,7M 0
5653 182,24,8,7M 0
5662 8,182,24,7M 0
5663 8,182,24,7M 0
5957 24,167,7M 0
5958 24,9,7M 0
5959 9,24,7M 0
5960 9,24,7M 0
5961 24,9,7M 0
5971 24,167,7M 0
6421 558,7,24,39,1M 0
6422 558,24,7,167,1M 0
6423 558,24,7,167,1M 0
6424 558,24,7,167,1M 0
6430 9,24,7,558,1M 0
6431 9,24,7,558,1M 0
6717 24,584,7,167,1M 0
6718 7,24,584,167,1M 0
6719 167,24,7,584,1M 0
7250 167,24,585,7M 0
7251 167,24,585,7M 0
7252 167,24,585,7M 0
7253 167,24,585,7M 0
7254 9,24,585,7M 0
7255 9,24,585,7M 0
7262 39,7,585,24M 0
7926 39,24,16,7M 0