SELECT 
  DISTINCT pc.category_id, 
  count(DISTINCT pc.product_id) as total_products 
FROM 
  cscart_products AS products 
  LEFT JOIN cscart_products_categories AS pc ON products.product_id = pc.product_id 
  LEFT JOIN cscart_products_categories AS ab__products_categories ON ab__products_categories.product_id = products.product_id 
  LEFT JOIN cscart_product_features_values AS product_features_values_657 ON product_features_values_657.product_id = products.product_id 
  AND product_features_values_657.feature_id = 657 
WHERE 
  1 
  AND ab__products_categories.category_id IN (561, 563) 
  AND product_features_values_657.variant_id = 6275 
GROUP BY 
  pc.category_id

Query time 0.00628

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "52.70"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.87"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "product_features_values_657",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "fl",
              "variant_id",
              "product_id",
              "fpl",
              "idx_product_feature_variant_id"
            ],
            "key": "variant_id",
            "used_key_parts": [
              "variant_id"
            ],
            "key_length": "3",
            "ref": [
              "const"
            ],
            "rows_examined_per_scan": 105,
            "rows_produced_per_join": 18,
            "filtered": "17.82",
            "cost_info": {
              "read_cost": "26.25",
              "eval_cost": "1.87",
              "prefix_cost": "36.75",
              "data_read_per_join": "14K"
            },
            "used_columns": [
              "feature_id",
              "product_id",
              "variant_id"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`product_features_values_657`.`feature_id` = 657) and (`softwarepirmam_hewadelivard_cscart_4`.`product_features_values_657`.`product_id` is not null))"
          }
        },
        {
          "table": {
            "table_name": "ab__products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.product_features_values_657.product_id"
            ],
            "rows_examined_per_scan": 2,
            "rows_produced_per_join": 0,
            "filtered": "2.50",
            "cost_info": {
              "read_cost": "9.36",
              "eval_cost": "0.09",
              "prefix_cost": "49.85",
              "data_read_per_join": "14"
            },
            "used_columns": [
              "product_id",
              "category_id"
            ],
            "attached_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`ab__products_categories`.`category_id` in (561,563))"
          }
        },
        {
          "table": {
            "table_name": "products",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.product_features_values_657.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "0.23",
              "eval_cost": "0.09",
              "prefix_cost": "50.18",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "product_id"
            ]
          }
        },
        {
          "table": {
            "table_name": "pc",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.product_features_values_657.product_id"
            ],
            "rows_examined_per_scan": 2,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.47",
              "eval_cost": "0.19",
              "prefix_cost": "50.83",
              "data_read_per_join": "29"
            },
            "used_columns": [
              "product_id",
              "category_id"
            ]
          }
        }
      ]
    }
  }
}

Result

category_id total_products
250 23
372 23
552 23
553 23
555 23
557 23
561 23
563 23