SELECT 
  cscart_ab__category_banners.*, 
  cscart_ab__category_banner_images_and_descr.category_banner, 
  cscart_ab__category_banner_images_and_descr.url, 
  cscart_ab__category_banner_images_and_descr.category_banner_image_id 
FROM 
  cscart_ab__category_banners 
  INNER JOIN cscart_ab__category_banner_images_and_descr ON cscart_ab__category_banner_images_and_descr.category_banner_id = cscart_ab__category_banners.category_banner_id 
  AND cscart_ab__category_banner_images_and_descr.lang_code = 'de' 
  LEFT JOIN cscart_ab__category_banner_categories AS ab__category_banner_categories ON ab__category_banner_categories.category_banner_id = cscart_ab__category_banners.category_banner_id 
  LEFT JOIN cscart_ab__category_banner_categories AS ab__category_banner_categories1 ON ab__category_banner_categories1.category_banner_id = cscart_ab__category_banners.category_banner_id 
  INNER JOIN cscart_images_links AS il ON il.object_type = 'category_banner' 
  AND il.object_id = cscart_ab__category_banner_images_and_descr.category_banner_image_id 
  AND il.pair_id IS NOT NULL 
  AND il.type = 'M' 
WHERE 
  1 
  AND cscart_ab__category_banners.status = 'A' 
  AND cscart_ab__category_banner_images_and_descr.category_banner_image_id IS NOT NULL 
  AND (
    IF(
      cscart_ab__category_banners.from_date, 
      cscart_ab__category_banners.from_date <= 1731701576, 
      1
    ) 
    AND IF(
      cscart_ab__category_banners.to_date, 
      cscart_ab__category_banners.to_date >= 1731701576, 
      1
    )
  ) 
  AND (
    ab__category_banner_categories.category_id = 448 
    OR (
      ab__category_banner_categories1.category_id IN (334, 448) 
      AND cscart_ab__category_banners.include_subcategories = 'Y'
    )
  ) 
ORDER BY 
  cscart_ab__category_banner_images_and_descr.category_banner asc

Query time 0.00127

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "4.65"
    },
    "ordering_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "0.45"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_ab__category_banners",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "status"
            ],
            "key": "status",
            "used_key_parts": [
              "status"
            ],
            "key_length": "3",
            "ref": [
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.00",
              "eval_cost": "0.20",
              "prefix_cost": "1.20",
              "data_read_per_join": "808"
            },
            "used_columns": [
              "category_banner_id",
              "status",
              "target_blank",
              "nofollow",
              "repeat",
              "position",
              "include_subcategories",
              "from_date",
              "to_date"
            ],
            "attached_condition": "(if(`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`from_date`,(`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`from_date` <= 1731701576),1) and if(`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`to_date`,(`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`to_date` >= 1731701576),1))"
          }
        },
        {
          "table": {
            "table_name": "cscart_ab__category_banner_images_and_descr",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "banner"
            ],
            "key": "banner",
            "used_key_parts": [
              "category_banner_id",
              "lang_code"
            ],
            "key_length": "9",
            "ref": [
              "eshopuga_upgr_4122.cscart_ab__category_banners.category_banner_id",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "50.00",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_ab__category_banner_images_and_descr`.`category_banner_image_id` is not null)",
            "cost_info": {
              "read_cost": "1.00",
              "eval_cost": "0.10",
              "prefix_cost": "2.40",
              "data_read_per_join": "776"
            },
            "used_columns": [
              "category_banner_image_id",
              "category_banner_id",
              "category_banner",
              "url",
              "lang_code"
            ]
          }
        },
        {
          "table": {
            "table_name": "ab__category_banner_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_banner_id"
            ],
            "key_length": "3",
            "ref": [
              "eshopuga_upgr_4122.cscart_ab__category_banners.category_banner_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "0.50",
              "eval_cost": "0.10",
              "prefix_cost": "3.00",
              "data_read_per_join": "4"
            },
            "used_columns": [
              "category_banner_id",
              "category_id"
            ],
            "attached_condition": "<if>(found_match(ab__category_banner_categories), ((`eshopuga_upgr_4122`.`ab__category_banner_categories`.`category_id` = 448) or (`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`include_subcategories` = 'Y')), true)"
          }
        },
        {
          "table": {
            "table_name": "ab__category_banner_categories1",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_banner_id"
            ],
            "key_length": "3",
            "ref": [
              "eshopuga_upgr_4122.cscart_ab__category_banners.category_banner_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "0.50",
              "eval_cost": "0.10",
              "prefix_cost": "3.60",
              "data_read_per_join": "4"
            },
            "used_columns": [
              "category_banner_id",
              "category_id"
            ],
            "attached_condition": "<if>(found_match(ab__category_banner_categories1), ((`eshopuga_upgr_4122`.`ab__category_banner_categories`.`category_id` = 448) or ((`eshopuga_upgr_4122`.`ab__category_banner_categories1`.`category_id` in (334,448)) and (`eshopuga_upgr_4122`.`cscart_ab__category_banners`.`include_subcategories` = 'Y'))), true)"
          }
        },
        {
          "table": {
            "table_name": "il",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "object_id"
            ],
            "key": "object_id",
            "used_key_parts": [
              "object_id",
              "object_type",
              "type"
            ],
            "key_length": "81",
            "ref": [
              "eshopuga_upgr_4122.cscart_ab__category_banner_images_and_descr.category_banner_image_id",
              "const",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "90.00",
            "index_condition": "(`eshopuga_upgr_4122`.`il`.`object_id` = `eshopuga_upgr_4122`.`cscart_ab__category_banner_images_and_descr`.`category_banner_image_id`)",
            "cost_info": {
              "read_cost": "0.50",
              "eval_cost": "0.09",
              "prefix_cost": "4.20",
              "data_read_per_join": "43"
            },
            "used_columns": [
              "pair_id",
              "object_id",
              "object_type",
              "type"
            ],
            "attached_condition": "(`eshopuga_upgr_4122`.`il`.`pair_id` is not null)"
          }
        }
      ]
    }
  }
}