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 (
    9869, 9870, 9871, 9872, 9873, 9874, 9875, 
    9876, 9877, 9878, 9879, 9880, 9881, 
    9882, 9883, 9884, 9885, 9886, 9887, 
    9888, 9889, 9890, 9891, 9892, 9893, 
    9894, 9895, 9896, 9897, 9898, 9899, 
    9900
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00082

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "117.81"
    },
    "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": 33,
            "rows_produced_per_join": 33,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (9869,9870,9871,9872,9873,9874,9875,9876,9877,9878,9879,9880,9881,9882,9883,9884,9885,9886,9887,9888,9889,9890,9891,9892,9893,9894,9895,9896,9897,9898,9899,9900))",
            "cost_info": {
              "read_cost": "71.61",
              "eval_cost": "6.60",
              "prefix_cost": "78.21",
              "data_read_per_join": "528"
            },
            "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": "33.00",
              "eval_cost": "1.32",
              "prefix_cost": "117.81",
              "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
9869 512M
9870 383M
9871 512M
9872 383M
9873 383M
9874 419M
9875 419M
9876 419M
9877 419M
9878 419M
9879 419M
9880 419M
9881 419M
9882 419M
9883 419M
9884 419M
9885 419M
9886 419M
9887 419M
9888 419M
9889 419M
9890 419M
9891 419M
9892 419M
9893 419M
9894 419M
9895 419M
9896 419M
9897 419M
9898 419M
9899 419M
9900 512M