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 = 522 
WHERE 
  cscart_products_categories.product_id IN (
    6114, 5647, 6146, 6187, 5651, 6086, 6299, 
    6307, 5508, 6081, 6144, 6254, 6228, 
    6192, 6227, 6083, 6230, 6275, 6258, 
    6255, 6229, 6256, 6189, 6257, 6259, 
    6145, 5644, 6226, 6297, 6190, 6276, 
    6303, 6260, 6305, 6274, 6301, 10074, 
    10088, 10157, 6822
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00242

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "91.66"
    },
    "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": 71,
            "rows_produced_per_join": 71,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6114,5647,6146,6187,5651,6086,6299,6307,5508,6081,6144,6254,6228,6192,6227,6083,6230,6275,6258,6255,6229,6256,6189,6257,6259,6145,5644,6226,6297,6190,6276,6303,6260,6305,6274,6301,10074,10088,10157,6822))",
            "cost_info": {
              "read_cost": "34.86",
              "eval_cost": "7.10",
              "prefix_cost": "41.96",
              "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": 71,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "17.75",
              "eval_cost": "7.10",
              "prefix_cost": "66.81",
              "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": 3,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "17.75",
              "eval_cost": "0.36",
              "prefix_cost": "91.66",
              "data_read_per_join": "11K"
            },
            "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
5508 522,521,535M 0
5644 522,521,535M 0
5647 522,521,536M 0
5651 522,521,536M 0
6081 521,522,535M 0
6083 521,522,535M 0
6086 522,521,537M 0
6114 521,522,536M 0
6144 522,521,535M 0
6145 522,521,535M 0
6146 521,522,536M 0
6187 521,522,536M 0
6189 522,521,535M 0
6190 522,521,535M 0
6192 522,521,537M 0
6226 537M
6227 537M
6228 537M
6229 537M
6230 537M
6254 537M
6255 537M
6256 537M
6257 537M
6258 537M
6259 537M
6260 535M
6274 535M
6275 537M
6276 535M
6297 521,522,535M 0
6299 521,522,536M 0
6301 521,522,535M 0
6303 521,522,535M 0
6305 521,522,535M 0
6307 521,522,536M 0
6822 536M
10074 522M 0
10088 522M 0
10157 522M 0