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 (
    30766, 30767, 30769, 30770, 30771, 30772, 
    30773, 30774, 30775, 30776, 30777, 
    30778, 30779, 30781, 30782, 30783, 
    30784, 30785, 30786, 30787, 30788, 
    30789, 30790, 30791, 30792, 30793, 
    30794, 30795, 30796, 30797, 30798, 
    30799
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00093

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "136.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": 40,
            "rows_produced_per_join": 40,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (30766,30767,30769,30770,30771,30772,30773,30774,30775,30776,30777,30778,30779,30781,30782,30783,30784,30785,30786,30787,30788,30789,30790,30791,30792,30793,30794,30795,30796,30797,30798,30799))",
            "cost_info": {
              "read_cost": "80.01",
              "eval_cost": "8.00",
              "prefix_cost": "88.01",
              "data_read_per_join": "640"
            },
            "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": 8,
            "filtered": "20.00",
            "cost_info": {
              "read_cost": "40.00",
              "eval_cost": "1.60",
              "prefix_cost": "136.01",
              "data_read_per_join": "21K"
            },
            "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
30766 419M
30767 560M
30769 38M
30770 179M
30771 369,368M
30772 560M
30773 419M
30774 301M
30775 419M
30776 6M
30777 432M
30778 76M
30779 64M
30781 183M
30782 529M
30783 183M
30784 160M
30785 446M
30786 64M
30787 183M
30788 166M
30789 64M
30790 152M
30791 473M
30792 87M
30793 184M
30794 529M
30795 275M
30796 64M
30797 581M
30798 495,584M
30799 183M