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 = 166 
WHERE 
  cscart_products_categories.product_id IN (
    4570, 1615, 2228, 2593, 3743, 4567, 3112, 
    2441, 2877, 2938, 3944, 4598, 4752, 
    5250, 7616, 5919, 3569, 5817, 3033, 
    5923, 4503, 3104, 4138, 2177, 2942, 
    3664, 5936, 3126, 3370, 7293, 2203, 
    2618, 2788, 4225, 5837, 7279, 7617, 
    2649, 7620, 855
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00211

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "120.37"
    },
    "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": 135,
            "rows_produced_per_join": 135,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (4570,1615,2228,2593,3743,4567,3112,2441,2877,2938,3944,4598,4752,5250,7616,5919,3569,5817,3033,5923,4503,3104,4138,2177,2942,3664,5936,3126,3370,7293,2203,2618,2788,4225,5837,7279,7617,2649,7620,855))",
            "cost_info": {
              "read_cost": "57.26",
              "eval_cost": "13.50",
              "prefix_cost": "70.76",
              "data_read_per_join": "2K"
            },
            "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": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "33.75",
              "eval_cost": "0.68",
              "prefix_cost": "118.01",
              "data_read_per_join": "21K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`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",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 6,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.69",
              "eval_cost": "0.68",
              "prefix_cost": "120.37",
              "data_read_per_join": "108"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
855 329,166,344M 0
1615 166,378,379M 0
2177 386,350,308,250,166,382M 0
2203 351,166,430M 0
2228 166,424,450,423M 0
2441 454,453,166,372,174,190M 0
2593 329,166,457M 0
2618 329,166,457M 0
2649 167,166,444M 0
2788 329,166,344M 0
2877 329,166,344M 0
2938 329,166,347M 0
2942 166,378,379M 0
3033 320,166,469M 0
3104 329,166,457M 0
3112 423,424,452,166M 0
3126 423,424,451,166M 0
3370 166,378,490M 0
3569 167,166,354M 0
3664 423,424,450,166M 0
3743 423,166,448M 0
3944 425,423,166M 0
4138 513,166,517M 0
4225 308,386,250,350,166,382M 0
4503 513,166,515M 0
4567 170,166,526M 0
4570 170,166,526M 0
4598 513,166,515M 0
4752 166,405,402,250,342,328,410,362M 0
5250 328,402,405,342,410,166,250,362M 0
5817 362,405,402,250,342,328,166,410M 0
5837 410,405,402,250,342,328,166,362M 0
5919 410,405,402,250,342,328,166,362M 0
5923 565,402,250,328,166,564M 0
5936 545,543,406,521,547,569,402,250,328,166,544M 0
7279 190,454M
7293 190,454M
7616 454,190M
7617 190,454M
7620 190,454M