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 (
    564, 565, 572, 574, 576, 605, 607, 610, 
    612, 613, 627, 663, 692, 708, 742, 810, 
    815, 816, 898, 817, 899, 900, 901, 909, 
    921
  ) 
  AND `P`.`status` = 'A' 
GROUP BY 
  `B`.`brand_id`, 
  `B`.`brand` 
ORDER BY 
  `B`.`brand` ASC 
LIMIT 
  0, 20

Query time 0.02840

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "9728.83"
    },
    "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": 6115,
              "rows_produced_per_join": 6115,
              "filtered": "100.00",
              "using_index": true,
              "cost_info": {
                "read_cost": "613.44",
                "eval_cost": "611.50",
                "prefix_cost": "1224.94",
                "data_read_per_join": "95K"
              },
              "used_columns": [
                "product_id",
                "category_id",
                "link_type"
              ],
              "attached_condition": "((`dev2`.`PC`.`category_id` in (564,565,572,574,576,605,607,610,612,613,627,663,692,708,742,810,815,816,898,817,899,900,901,909,921)) 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": 4416,
              "filtered": "72.23",
              "cost_info": {
                "read_cost": "1528.75",
                "eval_cost": "441.66",
                "prefix_cost": "3365.19",
                "data_read_per_join": "32M"
              },
              "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": 4416,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "1104.16",
                "eval_cost": "441.66",
                "prefix_cost": "4911.01",
                "data_read_per_join": "14M"
              },
              "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": 4475,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "1118.96",
                "eval_cost": "447.58",
                "prefix_cost": "6477.55",
                "data_read_per_join": "104K"
              },
              "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": 4475,
              "filtered": "100.00",
              "cost_info": {
                "read_cost": "2803.69",
                "eval_cost": "447.58",
                "prefix_cost": "9728.83",
                "data_read_per_join": "16M"
              },
              "used_columns": [
                "id",
                "path"
              ]
            }
          }
        ]
      }
    }
  }
}

Result

brand_id brand image category_id
170 BAWOO 742
176 BEAVER 742
224 BOBCAT 742
234 BORUS https://s3.timeweb.cloud/482029f9-prod/brands__images/234_da67c1403b1a_jme26iyy2weil11sz6qjcuqd1cfoxa54.png 572
289 CARTER 574
291 CASE https://s3.timeweb.cloud/482029f9-prod/brands__images/291_b2f835d9024d_case.png 565
293 CATERPILLAR 565
312 CHANGLIN 572
366 CUKUROVA https://s3.timeweb.cloud/482029f9-prod/brands__images/366_b98004d221e7_Cukurova.png 605
378 DAHAN 921
453 DONGYANG 576
455 DOOSAN https://s3.timeweb.cloud/482029f9-prod/brands__images/455_79188a46da42_DOOSAN.jpeg 572
557 EVERDIGM 898
560 EVERUN 572
584 FAW https://s3.timeweb.cloud/482029f9-prod/brands__images/584_393dc2db8548_faw.png 576
609 FIORI 607
641 FUKAI 572
659 GEHL 605
745 HANK 607
751 HANSIN 612