SELECT 
  SQL_CALC_FOUND_ROWS `B`.`brand_id`, 
  `B`.`brand`, 
  COALESCE(F.path, "") AS image, 
  `PC`.`category_id` 
FROM 
  `cscart_brands` AS `B` 
  LEFT JOIN `files__images` AS `FI` ON `B`.`brand_id` = `FI`.`object_id` 
  AND `FI`.`object_type` = "brand" 
  LEFT JOIN `files` AS `F` ON `F`.`id` = `FI`.`file_id` 
  LEFT JOIN `cscart_products` AS `P` ON `B`.`brand_id` = `P`.`brand_id` 
  LEFT JOIN `cscart_products_categories` AS `PC` ON `PC`.`product_id` = `P`.`product_id` 
  AND `PC`.`link_type` = 'M' 
WHERE 
  1 
  AND `PC`.`category_id` IN (
    293, 294, 328, 329, 330, 331, 332, 295, 
    333, 334, 335, 336, 296, 297, 337, 338, 
    339, 340, 298, 341, 342, 343, 344, 345, 
    346, 299, 347, 348, 349, 350, 351, 352, 
    353, 354, 355, 356, 300, 357, 358, 359, 
    360, 361, 301, 362, 363, 364, 302, 365, 
    366, 367, 368, 303, 304, 369, 370, 371, 
    305, 306, 307, 372, 373, 374, 375, 376, 
    308, 377, 378, 379, 380, 309, 310, 311, 
    313, 314, 315, 316, 317, 386, 387, 388, 
    318, 319, 320, 389, 390, 321, 322, 323, 
    324, 391, 392, 393, 325, 394, 395, 396, 
    326, 427, 919, 428, 429, 557, 632, 634, 
    918
  ) 
  AND `P`.`status` = 'A' 
GROUP BY 
  `B`.`brand_id`, 
  `B`.`brand` 
ORDER BY 
  `B`.`brand` ASC 
LIMIT 
  0, 20

Query time 0.00360

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "1448.12"
    },
    "ordering_operation": {
      "using_filesort": true,
      "grouping_operation": {
        "using_temporary_table": true,
        "using_filesort": false,
        "nested_loop": [
          {
            "table": {
              "table_name": "PC",
              "access_type": "range",
              "possible_keys": [
                "PRIMARY",
                "link_type",
                "pt",
                "idx_pc_product_id_type"
              ],
              "key": "link_type",
              "used_key_parts": [
                "link_type",
                "category_id"
              ],
              "key_length": "6",
              "rows_examined_per_scan": 910,
              "rows_produced_per_join": 910,
              "filtered": "100.00",
              "using_index": true,
              "cost_info": {
                "read_cost": "91.51",
                "eval_cost": "91.00",
                "prefix_cost": "182.51",
                "data_read_per_join": "14K"
              },
              "used_columns": [
                "product_id",
                "category_id",
                "link_type"
              ],
              "attached_condition": "((`dev2`.`PC`.`category_id` in (293,294,328,329,330,331,332,295,333,334,335,336,296,297,337,338,339,340,298,341,342,343,344,345,346,299,347,348,349,350,351,352,353,354,355,356,300,357,358,359,360,361,301,362,363,364,302,365,366,367,368,303,304,369,370,371,305,306,307,372,373,374,375,376,308,377,378,379,380,309,310,311,313,314,315,316,317,386,387,388,318,319,320,389,390,321,322,323,324,391,392,393,325,394,395,396,326,427,919,428,429,557,632,634,918)) and (`dev2`.`PC`.`link_type` = 'M'))"
            }
          },
          {
            "table": {
              "table_name": "P",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "status",
                "cscart_products_brand_id_index",
                "cscart_products_product_id_index",
                "idx_status"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "product_id"
              ],
              "key_length": "3",
              "ref": [
                "dev2.PC.product_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 657,
              "filtered": "72.23",
              "cost_info": {
                "read_cost": "227.50",
                "eval_cost": "65.73",
                "prefix_cost": "501.01",
                "data_read_per_join": "4M"
              },
              "used_columns": [
                "product_id",
                "status",
                "brand_id"
              ],
              "attached_condition": "((`dev2`.`P`.`status` = 'A') and (`dev2`.`P`.`brand_id` is not null))"
            }
          },
          {
            "table": {
              "table_name": "B",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY",
                "cscart_brands_pk2"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "brand_id"
              ],
              "key_length": "4",
              "ref": [
                "dev2.P.brand_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 657,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "164.31",
                "eval_cost": "65.73",
                "prefix_cost": "731.05",
                "data_read_per_join": "2M"
              },
              "used_columns": [
                "brand_id",
                "brand"
              ]
            }
          },
          {
            "table": {
              "table_name": "FI",
              "access_type": "ref",
              "possible_keys": [
                "idx_fi_object_id_type"
              ],
              "key": "idx_fi_object_id_type",
              "used_key_parts": [
                "object_id",
                "object_type"
              ],
              "key_length": "5",
              "ref": [
                "dev2.P.brand_id",
                "const"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 666,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "166.52",
                "eval_cost": "66.61",
                "prefix_cost": "964.17",
                "data_read_per_join": "15K"
              },
              "used_columns": [
                "object_id",
                "object_type",
                "file_id"
              ]
            }
          },
          {
            "table": {
              "table_name": "F",
              "access_type": "eq_ref",
              "possible_keys": [
                "PRIMARY"
              ],
              "key": "PRIMARY",
              "used_key_parts": [
                "id"
              ],
              "key_length": "4",
              "ref": [
                "dev2.FI.file_id"
              ],
              "rows_examined_per_scan": 1,
              "rows_produced_per_join": 666,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "417.34",
                "eval_cost": "66.61",
                "prefix_cost": "1448.12",
                "data_read_per_join": "2M"
              },
              "used_columns": [
                "id",
                "path"
              ]
            }
          }
        ]
      }
    }
  }
}

Result

brand_id brand image category_id
3149 Bitmain 918
320 CHL 388
977 KAISHAN 329
1482 PRIDE 329
1811 SUNWARD https://s3.timeweb.cloud/482029f9-prod/brands__images/1811_5895bbbe6036_Sunward.png 329
2097 XCMG https://s3.timeweb.cloud/482029f9-prod/brands__images/2097_5db562fc42b7_xcmg.png 329
2143 YUTONG https://s3.timeweb.cloud/482029f9-prod/brands__images/2143_e4624e339f4f_yutong.jpeg 329