SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    515, 514, 513, 512, 511, 510, 509, 508, 
    507, 506, 505, 504, 503, 502, 501, 499, 
    500, 498, 497, 496, 495, 494, 493, 492, 
    491, 490, 489, 488, 487, 486, 485, 484, 
    483, 482, 481, 480, 479, 478, 477, 476, 
    475, 474, 473, 472, 471, 470, 469, 468
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00084

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "43.59"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "2.99"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 98,
            "rows_produced_per_join": 3,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "22.49",
              "eval_cost": "0.78",
              "prefix_cost": "23.28",
              "data_read_per_join": "13K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`danishecarter_latest`.`cscart_categories`.`storefront_id` in (0,1)) and ((`danishecarter_latest`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`danishecarter_latest`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`danishecarter_latest`.`cscart_categories`.`usergroup_ids`)) and (`danishecarter_latest`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "danishecarter_latest.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 3,
            "rows_produced_per_join": 2,
            "filtered": "25.39",
            "index_condition": "(`danishecarter_latest`.`cscart_products_categories`.`product_id` in (515,514,513,512,511,510,509,508,507,506,505,504,503,502,501,499,500,498,497,496,495,494,493,492,491,490,489,488,487,486,485,484,483,482,481,480,479,478,477,476,475,474,473,472,471,470,469,468))",
            "cost_info": {
              "read_cost": "14.97",
              "eval_cost": "0.60",
              "prefix_cost": "40.60",
              "data_read_per_join": "47"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
468 302M
469 305M
470 303M
471 303M
472 302M
473 303M
474 303M
475 303M
476 305M
477 302M
478 302M
479 302M
480 302M
481 303M
482 306M
483 305M
484 303M
485 302M
486 303M
487 302M
488 302M
489 303M
490 303M
491 303M
492 302M
493 303M
494 296M
495 296M
496 297M
497 297M
498 297M
499 297M
500 297M
501 297M
502 297M
503 297M
504 297M
505 297M
506 297M
507 297M
508 297M
509 297M
510 297M
511 297M
512 297M
513 297M
514 297M
515 297M