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, 
  product_position_source.position AS position 
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') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 321 
WHERE 
  cscart_products_categories.product_id IN (
    520, 521, 522, 523, 524, 525, 526, 527, 
    528, 529, 530, 531, 532, 533, 534, 535, 
    536, 537, 538, 539, 540, 541, 542, 543, 
    544, 545, 546, 547, 548, 549, 550, 551, 
    552, 553, 554, 555, 556, 557, 558, 559, 
    560, 561, 562, 563, 564, 565, 566, 567, 
    587, 585, 583, 586, 584, 519
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00101

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "47.66"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.96"
      },
      "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.50",
              "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": 4,
            "rows_produced_per_join": 1,
            "filtered": "12.50",
            "index_condition": "(`danishecarter_latest`.`cscart_products_categories`.`product_id` in (520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,587,585,583,586,584,519))",
            "cost_info": {
              "read_cost": "16.93",
              "eval_cost": "0.39",
              "prefix_cost": "43.35",
              "data_read_per_join": "31"
            },
            "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",
              "danishecarter_latest.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.96",
              "eval_cost": "0.39",
              "prefix_cost": "45.70",
              "data_read_per_join": "31"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
519 330M
520 330M
521 331M
522 330M
523 325M
524 325M
525 325M
526 330M
527 330M
528 333M
529 333M
530 333M
531 333M
532 333M
533 330M
534 330M
535 331M
536 331M
537 330M
538 330M
539 331M
540 331M
541 330M
542 330M
543 331M
544 331M
545 325M
546 325M
547 325M
548 325M
549 325M
550 325M
551 325M
552 325M
553 325M
554 325M
555 325M
556 325M
557 325M
558 325M
559 325M
560 325M
561 325M
562 325M
563 325M
564 325M
565 327M
566 327M
567 322M
583 323M
584 323M
585 330M
586 323M
587 331M