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 = 621 
WHERE 
  cscart_products_categories.product_id IN (
    8007, 7724, 7897, 7952, 7959, 7972, 7974, 
    8009, 8010, 7948, 7949, 7953, 7962, 
    7964, 7968, 8005, 8013, 7231, 7249, 
    7391, 7947, 7955, 7957, 7958, 7975, 
    7992, 7024, 7355, 7893, 7954, 7970, 
    7977, 7196, 7350, 8080, 7227, 7324, 
    7500, 7956, 8006, 7022, 7080, 7191, 
    7250, 7320, 7340, 7352, 7888, 8110, 
    8192, 8364, 7021, 7192, 7256, 7506, 
    7850, 7230, 7319, 7343, 7386, 7900, 
    8214, 7189, 7226, 7348, 7356, 7390, 
    7965, 7232, 7237, 7344, 7383, 7389, 
    7887, 7894, 8207, 9909, 7193, 7262, 
    8069
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00324

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "140.76"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 105,
            "rows_produced_per_join": 105,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (8007,7724,7897,7952,7959,7972,7974,8009,8010,7948,7949,7953,7962,7964,7968,8005,8013,7231,7249,7391,7947,7955,7957,7958,7975,7992,7024,7355,7893,7954,7970,7977,7196,7350,8080,7227,7324,7500,7956,8006,7022,7080,7191,7250,7320,7340,7352,7888,8110,8192,8364,7021,7192,7256,7506,7850,7230,7319,7343,7386,7900,8214,7189,7226,7348,7356,7390,7965,7232,7237,7344,7383,7389,7887,7894,8207,9909,7193,7262,8069))",
            "cost_info": {
              "read_cost": "56.76",
              "eval_cost": "10.50",
              "prefix_cost": "67.26",
              "data_read_per_join": "1K"
            },
            "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",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 105,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "26.25",
              "eval_cost": "10.50",
              "prefix_cost": "104.01",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 5,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "26.25",
              "eval_cost": "0.53",
              "prefix_cost": "140.76",
              "data_read_per_join": "16K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
7021 623M
7022 623M
7024 623M
7080 623M
7189 623M
7191 623M
7192 623M
7193 623M
7196 623M
7226 623M
7227 623M
7230 623M
7231 623M
7232 623M
7237 623M
7249 623M
7250 623M
7256 623M
7262 623M
7319 623M
7320 623M
7324 623M
7340 623M
7343 623M
7344 623M
7348 623M
7350 623M
7352 623M
7355 623M
7356 623M
7383 623M
7386 623M
7389 623M
7390 623M
7391 623M
7500 623M
7506 623M
7724 623,622,625M
7850 623,622,625M
7887 623,622,625M
7888 623,622,625M
7893 623,622,625M
7894 623,622,625M
7897 623,622,625M
7900 623,622,625M
7947 626M
7948 626M
7949 626M
7952 626M
7953 626M
7954 626M
7955 626M
7956 626M
7957 626M
7958 626M
7959 626M
7962 626M
7964 627M
7965 622,623,627M
7968 622,623,627M
7970 622,623,627M
7972 622,623,627M
7974 627M
7975 627M
7977 627M
7992 623M
8005 627M
8006 627M
8007 627M
8009 627M
8010 627M
8013 627M
8069 623,622,625M
8080 623,622,625M
8110 623,622,625M
8192 623,622,625M
8207 623,622,625M
8214 623,622,625M
8364 623M
9909 622M