SELECT 
  c.category_id, 
  IF(pc.link_type = 'M', 1, 0) as is_main 
FROM 
  cscart_categories AS c 
  LEFT JOIN cscart_products_categories AS pc ON c.category_id = pc.category_id 
WHERE 
  pc.product_id = 7819 
  AND c.company_id = 1 
ORDER BY 
  is_main DESC

Query time 0.00019

JSON explain

{
  "query_block": {
    "select_id": 1,
    "read_sorted_file": {
      "filesort": {
        "sort_key": "if(pc.link_type = 'M',1,0) desc",
        "table": {
          "table_name": "pc",
          "access_type": "ref",
          "possible_keys": ["PRIMARY", "pt"],
          "key": "pt",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "ref": ["const"],
          "rows": 2,
          "filtered": 100,
          "attached_condition": "pc.product_id <=> 7819"
        }
      }
    },
    "table": {
      "table_name": "c",
      "access_type": "eq_ref",
      "possible_keys": ["PRIMARY", "p_category_id"],
      "key": "PRIMARY",
      "key_length": "3",
      "used_key_parts": ["category_id"],
      "ref": ["rfswire_cart.pc.category_id"],
      "rows": 1,
      "filtered": 100,
      "attached_condition": "c.company_id = 1"
    }
  }
}

Result

category_id is_main
3871 1