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 = 7184 
WHERE 
  cscart_products_categories.product_id IN (
    101022, 101023, 101024, 101025, 101026, 
    101027, 101028, 101029, 101030, 101031, 
    101032, 101033, 101034, 101035, 101107, 
    101108, 101109, 101110, 101111, 101116, 
    101117, 101118, 101119, 101120, 101125, 
    101126, 101127, 101128, 101129, 101509, 
    101510, 101511, 101512, 101513, 101518, 
    101519, 101520, 101521, 101522, 101527, 
    101528, 101529, 101530, 101531, 101547, 
    101548, 101549, 101550, 101551, 101556, 
    101557, 101558, 101559, 101560, 101565, 
    101566, 101567, 101568, 101569, 101794, 
    101795, 101796, 101797, 101798, 101799, 
    101800, 101801, 101802, 101803, 101804, 
    101805, 101806, 101807, 101808, 101809, 
    101810, 101811, 101812, 101813
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00220

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "53.07"
    },
    "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": 93,
            "rows_produced_per_join": 93,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "9.59",
              "eval_cost": "9.30",
              "prefix_cost": "18.89",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (101022,101023,101024,101025,101026,101027,101028,101029,101030,101031,101032,101033,101034,101035,101107,101108,101109,101110,101111,101116,101117,101118,101119,101120,101125,101126,101127,101128,101129,101509,101510,101511,101512,101513,101518,101519,101520,101521,101522,101527,101528,101529,101530,101531,101547,101548,101549,101550,101551,101556,101557,101558,101559,101560,101565,101566,101567,101568,101569,101794,101795,101796,101797,101798,101799,101800,101801,101802,101803,101804,101805,101806,101807,101808,101809,101810,101811,101812,101813))"
          }
        },
        {
          "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": "23.25",
              "eval_cost": "0.47",
              "prefix_cost": "51.44",
              "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.16",
              "eval_cost": "0.47",
              "prefix_cost": "53.07",
              "data_read_per_join": "74"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
101022 7337,7217M
101023 7337,7217M
101024 7337,7217M
101025 7337,7217M
101026 7337,7217M
101027 7337,7217M
101028 7337,7217M
101029 7337,7217M
101030 7337,7217M
101031 7337,7217M
101032 7337,7217M
101033 7337,7217M
101034 7337,7217M
101035 7337,7217M
101107 7185M
101108 7185M
101109 7185M
101110 7186M
101111 7186M
101116 7185M
101117 7185M
101118 7185M
101119 7186M
101120 7186M
101125 7185M
101126 7185M
101127 7185M
101128 7186M
101129 7186M
101509 7185M
101510 7185M
101511 7185M
101512 7186M
101513 7186M
101518 7185M
101519 7185M
101520 7185M
101521 7186M
101522 7186M
101527 7185M
101528 7185M
101529 7185M
101530 7186M
101531 7186M
101547 7185M
101548 7185M
101549 7185M
101550 7186M
101551 7186M
101556 7185M
101557 7185M
101558 7185M
101559 7186M
101560 7186M
101565 7185M
101566 7185M
101567 7185M
101568 7186M
101569 7186M
101794 7186M
101795 7186M
101796 7186M
101797 7186M
101798 7186M
101799 7186M
101800 7186M
101801 7186M
101802 7186M
101803 7186M
101804 7185M
101805 7185M
101806 7185M
101807 7185M
101808 7185M
101809 7185M
101810 7185M
101811 7185M
101812 7185M
101813 7185M