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 (
    9677, 9678, 9679, 9680, 9681, 9682, 9683, 
    9684, 9685, 9686, 9687, 9688, 9689, 
    9690, 9691, 9692, 9693, 9694, 9695, 
    9696, 9697, 9698, 9699, 9700, 9701, 
    9702, 9703, 9704, 9705, 9706, 9707, 
    9708
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00080

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "120.41"
    },
    "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": 34,
            "rows_produced_per_join": 34,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (9677,9678,9679,9680,9681,9682,9683,9684,9685,9686,9687,9688,9689,9690,9691,9692,9693,9694,9695,9696,9697,9698,9699,9700,9701,9702,9703,9704,9705,9706,9707,9708))",
            "cost_info": {
              "read_cost": "72.81",
              "eval_cost": "6.80",
              "prefix_cost": "79.61",
              "data_read_per_join": "544"
            },
            "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": 6,
            "filtered": "20.00",
            "cost_info": {
              "read_cost": "34.00",
              "eval_cost": "1.36",
              "prefix_cost": "120.41",
              "data_read_per_join": "17K"
            },
            "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
9677 418M
9678 418M
9679 418M
9680 192M
9681 192M
9682 562M
9683 562M
9684 562M
9685 195,199M
9686 418M
9687 191M
9688 418M
9689 418M
9690 418M
9691 418M
9692 418M
9693 192M
9694 192M
9695 192M
9696 418M
9697 418M
9698 418M
9699 418M
9700 191M
9701 418M
9702 191M
9703 418M
9704 418M
9705 191M
9706 418M
9707 418M
9708 418M