SELECT 
  q_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      q_products_categories.link_type = "M", 
      CONCAT(
        q_products_categories.category_id, 
        "M"
      ), 
      q_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  q_products_categories 
  INNER JOIN q_categories ON q_categories.category_id = q_products_categories.category_id 
  AND (
    q_categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, q_categories.usergroup_ids) 
    OR FIND_IN_SET(1, q_categories.usergroup_ids)
  ) 
  AND q_categories.status IN ('A', 'H') 
WHERE 
  q_products_categories.product_id IN (
    32817, 32818, 32819, 32820, 32821, 32822, 
    32823, 32824, 32825, 32826, 32827, 
    32828, 32829, 32830, 32831, 32832, 
    32833, 32834, 32835, 32836, 32837, 
    32838, 32839, 32840, 32841, 32842, 
    32843, 32844, 32845, 32846, 32847, 
    32848
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00134

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "175.01"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "q_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 55,
            "rows_produced_per_join": 55,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (32817,32818,32819,32820,32821,32822,32823,32824,32825,32826,32827,32828,32829,32830,32831,32832,32833,32834,32835,32836,32837,32838,32839,32840,32841,32842,32843,32844,32845,32846,32847,32848))",
            "cost_info": {
              "read_cost": "98.01",
              "eval_cost": "11.00",
              "prefix_cost": "109.01",
              "data_read_per_join": "880"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "q_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "portal.q_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 11,
            "filtered": "20.00",
            "cost_info": {
              "read_cost": "55.00",
              "eval_cost": "2.20",
              "prefix_cost": "175.01",
              "data_read_per_join": "29K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "(((`portal`.`q_categories`.`usergroup_ids` = '') or find_in_set(0,`portal`.`q_categories`.`usergroup_ids`) or find_in_set(1,`portal`.`q_categories`.`usergroup_ids`)) and (`portal`.`q_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
32817 96M
32818 96M
32819 96M
32820 96M
32821 97M
32822 97M
32823 97M
32824 97M
32825 96M
32826 96M
32827 96M
32828 96M
32829 96M
32830 96M
32831 96M
32832 96M
32833 96M
32834 97M
32835 97M
32836 97M
32837 97M
32838 97M
32839 97M
32840 97M
32841 97M
32842 97M
32843 97M
32844 97M
32845 97M
32846 97M
32847 97M
32848 97M