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 (
    9966, 9967, 9968, 9969, 9970, 9971, 9972, 
    9973, 9974, 9975, 9976, 9977, 9978, 
    9979, 9980, 9981, 9982, 9983, 7798, 
    7797, 7779, 7778, 7777, 7776, 7775, 
    7772, 7771, 6913, 6914, 6915, 6916, 
    6917
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00088

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 (9966,9967,9968,9969,9970,9971,9972,9973,9974,9975,9976,9977,9978,9979,9980,9981,9982,9983,7798,7797,7779,7778,7777,7776,7775,7772,7771,6913,6914,6915,6916,6917))",
            "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
6913 512M
6914 413M
6915 512M
6916 512M
6917 512M
7771 177M
7772 177M
7775 177M
7776 177M
7777 177M
7778 177M
7779 177M
7797 177M
7798 177M
9966 383M
9967 419M
9968 419M
9969 551M
9970 385M
9971 193M
9972 419M
9973 419M
9974 419M
9975 419M
9976 419M
9977 419M
9978 419M
9979 193M
9980 193M
9981 193M
9982 194M
9983 193M