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, 
  product_position_source.position AS position 
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') 
  LEFT JOIN q_products_categories AS product_position_source ON q_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 300 
WHERE 
  q_products_categories.product_id IN (
    6415, 6416, 6417, 6418, 6419, 6420, 6421, 
    6422, 6423, 6424, 6425, 6426, 6427, 
    6428, 6429, 6430, 6431, 6432, 6433, 
    6434, 6435, 6436, 6437, 6438, 6439, 
    6440, 6441, 6442, 6443, 6444, 6445, 
    6446, 6447, 6448, 6449, 6450, 6451, 
    6452, 6453, 6454, 6456, 6457, 6458, 
    6459, 6460, 6461, 6462, 6463, 6464, 
    6465, 6466, 6467, 6468, 6469, 6470, 
    6471, 6472, 6473, 6474, 6475, 6476, 
    6477, 6478, 6479
  ) 
GROUP BY 
  q_products_categories.product_id

Query time 0.00136

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "307.21"
    },
    "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": 64,
            "rows_produced_per_join": 64,
            "filtered": "100.00",
            "index_condition": "(`portal`.`q_products_categories`.`product_id` in (6415,6416,6417,6418,6419,6420,6421,6422,6423,6424,6425,6426,6427,6428,6429,6430,6431,6432,6433,6434,6435,6436,6437,6438,6439,6440,6441,6442,6443,6444,6445,6446,6447,6448,6449,6450,6451,6452,6453,6454,6456,6457,6458,6459,6460,6461,6462,6463,6464,6465,6466,6467,6468,6469,6470,6471,6472,6473,6474,6475,6476,6477,6478,6479))",
            "cost_info": {
              "read_cost": "140.81",
              "eval_cost": "12.80",
              "prefix_cost": "153.61",
              "data_read_per_join": "1024"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "portal.q_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 64,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "64.00",
              "eval_cost": "12.80",
              "prefix_cost": "230.41",
              "data_read_per_join": "1024"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "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": 12,
            "filtered": "20.00",
            "cost_info": {
              "read_cost": "64.00",
              "eval_cost": "2.56",
              "prefix_cost": "307.21",
              "data_read_per_join": "33K"
            },
            "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 position
6415 430M
6416 430M
6417 430M
6418 430M
6419 430M
6420 430M
6421 430M
6422 430M
6423 430M
6424 430M
6425 430M
6426 430M
6427 430M
6428 430M
6429 430M
6430 430M
6431 430M
6432 430M
6433 430M
6434 430M
6435 430M
6436 430M
6437 430M
6438 430M
6439 430M
6440 430M
6441 430M
6442 430M
6443 430M
6444 410M
6445 410M
6446 410M
6447 410M
6448 390M
6449 376M
6450 599M
6451 300M 0
6452 390M
6453 390M
6454 390M
6456 390M
6457 390M
6458 390M
6459 376M
6460 376M
6461 376M
6462 376M
6463 376M
6464 376M
6465 376M
6466 376M
6467 376M
6468 599M
6469 599M
6470 599M
6471 599M
6472 375M
6473 410M
6474 573M
6475 410M
6476 410M
6477 573M
6478 573M
6479 573M