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 (
    47678, 
    47679, 
    47680, 
    47681, 
    47682, 
    47683, 
    47684, 
    47685, 
    47686, 
    47688, 
    47690, 
    47691, 
    47692, 
    47693, 
    47694, 
    47695, 
    47696, 
    47697, 
    47698, 
    47699, 
    47700, 
    47701, 
    47702, 
    47703, 
    47705, 
    47706, 
    47707, 
    47708, 
    47709, 
    47710, 
    47711, 
    47712, 
    47714, 
    47719, 
    47720, 
    47721, 
    47722, 
    47725, 
    47730, 
    47731, 
    47732, 
    47733, 
    47734, 
    47735, 
    47736, 
    47737, 
    47738, 
    47739, 
    47740, 
    47741, 
    47742, 
    47743, 
    47744, 
    47745, 
    47746, 
    47747, 
    47748, 
    47749, 
    47750, 
    47751, 
    47752, 
    47753, 
    47754, 
    47755, 
    47756, 
    47757, 
    47758, 
    47760, 
    47761, 
    47762, 
    47763, 
    47764, 
    47765, 
    47766, 
    47767, 
    47768, 
    47769, 
    47770, 
    47771, 
    47772, 
    47773, 
    47774, 
    45784, 
    45785, 
    45786, 
    45787, 
    45788, 
    45789, 
    45790, 
    45791, 
    45792, 
    45793, 
    45794, 
    45795, 
    45796, 
    45797, 
    45798, 
    45799, 
    45800, 
    45801, 
    45802, 
    45803, 
    45804, 
    45805, 
    45806, 
    45807, 
    45808, 
    45809, 
    45810, 
    45811, 
    45812, 
    45813, 
    45814, 
    45815, 
    45816, 
    45817, 
    45818, 
    45819, 
    45820, 
    45821, 
    45822, 
    45823, 
    45824, 
    45825, 
    45826, 
    45827, 
    45828, 
    45829
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00180

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "463.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": 129,
            "rows_produced_per_join": 129,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (47678,47679,47680,47681,47682,47683,47684,47685,47686,47688,47690,47691,47692,47693,47694,47695,47696,47697,47698,47699,47700,47701,47702,47703,47705,47706,47707,47708,47709,47710,47711,47712,47714,47719,47720,47721,47722,47725,47730,47731,47732,47733,47734,47735,47736,47737,47738,47739,47740,47741,47742,47743,47744,47745,47746,47747,47748,47749,47750,47751,47752,47753,47754,47755,47756,47757,47758,47760,47761,47762,47763,47764,47765,47766,47767,47768,47769,47770,47771,47772,47773,47774,45784,45785,45786,45787,45788,45789,45790,45791,45792,45793,45794,45795,45796,45797,45798,45799,45800,45801,45802,45803,45804,45805,45806,45807,45808,45809,45810,45811,45812,45813,45814,45815,45816,45817,45818,45819,45820,45821,45822,45823,45824,45825,45826,45827,45828,45829))",
            "cost_info": {
              "read_cost": "282.81",
              "eval_cost": "25.80",
              "prefix_cost": "308.61",
              "data_read_per_join": "2K"
            },
            "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": 25,
            "filtered": "20.00",
            "cost_info": {
              "read_cost": "129.00",
              "eval_cost": "5.16",
              "prefix_cost": "463.41",
              "data_read_per_join": "68K"
            },
            "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
45784 584,474M
45785 474M
45786 470M
45787 474M
45788 472M
45789 472M
45790 472M
45791 472M
45792 472M
45793 472M
45794 472M
45795 472M
45796 472M
45797 472M
45798 475M
45799 475M
45800 475M
45801 475M
45802 475M
45803 475M
45804 475M
45805 564M
45806 472M
45807 472M
45808 472M
45809 472M
45810 472M
45811 474M
45812 474M
45813 470M
45814 470M
45815 470M
45816 470M
45817 470M
45818 470M
45819 470M
45820 470M
45821 470M
45822 474M
45823 474M
45824 474M
45825 474M
45826 474M
45827 470M
45828 475M
45829 472M
47678 257M
47679 615M
47680 615M
47681 615M
47682 615M
47683 615M
47684 615M
47685 615M
47686 257M
47688 615M
47690 257M
47691 615M
47692 257M
47693 257M
47694 615M
47695 615M
47696 615M
47697 257M
47698 257M
47699 257M
47700 257M
47701 257M
47702 615M
47703 257M
47705 615M
47706 615M
47707 615M
47708 615M
47709 615M
47710 615M
47711 615M
47712 615M
47714 615M
47719 615M
47720 615M
47721 615M
47722 615M
47725 615M
47730 615M
47731 615M
47732 615M
47733 615M
47734 615M
47735 615M
47736 615M
47737 615M
47738 615M
47739 615M
47740 615M
47741 615M
47742 615M
47743 615M
47744 615M
47745 615M
47746 615M
47747 615M
47748 615M
47749 615M
47750 615M
47751 615M
47752 615M
47753 469M
47754 469M
47755 469M
47756 469M
47757 469M
47758 469M
47760 469M
47761 469M
47762 469M
47763 301M
47764 469M
47765 469M
47766 615M
47767 469M
47768 469M
47769 566M
47770 64M
47771 257M
47772 408M
47773 615M
47774 615M