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 = 'en' 
  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 <= 1734487477, 
      1
    ) 
    AND IF(
      cscart_ab__category_banners.to_date, 
      cscart_ab__category_banners.to_date >= 1734487477, 
      1
    )
  ) 
  AND (
    ab__category_banner_categories.category_id = 3272 
    OR (
      ab__category_banner_categories1.category_id IN (3487, 3150, 3272) 
      AND cscart_ab__category_banners.include_subcategories = 'Y'
    )
  ) 
ORDER BY 
  cscart_ab__category_banner_images_and_descr.category_banner asc

Query time 0.00497

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "5.75"
    },
    "ordering_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.00"
      },
      "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.10",
              "prefix_cost": "1.10",
              "data_read_per_join": "808"
            },
            "used_columns": [
              "category_banner_id",
              "status",
              "target_blank",
              "repeat",
              "position",
              "include_subcategories",
              "from_date",
              "to_date",
              "nofollow"
            ],
            "attached_condition": "((0 <> if(`s2cart`.`cscart_ab__category_banners`.`from_date`,(`s2cart`.`cscart_ab__category_banners`.`from_date` <= 1734487477),1)) and (0 <> if(`s2cart`.`cscart_ab__category_banners`.`to_date`,(`s2cart`.`cscart_ab__category_banners`.`to_date` >= 1734487477),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": [
              "s2cart.cscart_ab__category_banners.category_banner_id",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.00",
              "eval_cost": "0.10",
              "prefix_cost": "2.20",
              "data_read_per_join": "1K"
            },
            "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": [
              "s2cart.cscart_ab__category_banners.category_banner_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "1.00",
              "eval_cost": "0.10",
              "prefix_cost": "3.30",
              "data_read_per_join": "8"
            },
            "used_columns": [
              "category_banner_id",
              "category_id"
            ],
            "attached_condition": "<if>(found_match(ab__category_banner_categories), ((`s2cart`.`ab__category_banner_categories`.`category_id` = 3272) or (`s2cart`.`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": [
              "s2cart.cscart_ab__category_banners.category_banner_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "1.00",
              "eval_cost": "0.10",
              "prefix_cost": "4.40",
              "data_read_per_join": "8"
            },
            "used_columns": [
              "category_banner_id",
              "category_id"
            ],
            "attached_condition": "<if>(found_match(ab__category_banner_categories1), ((`s2cart`.`ab__category_banner_categories`.`category_id` = 3272) or ((`s2cart`.`ab__category_banner_categories1`.`category_id` in (3487,3150,3272)) and (`s2cart`.`cscart_ab__category_banners`.`include_subcategories` = 'Y'))), true)"
          }
        },
        {
          "table": {
            "table_name": "il",
            "access_type": "ref",
            "possible_keys": [
              "object_id"
            ],
            "key": "object_id",
            "used_key_parts": [
              "object_id",
              "object_type",
              "type"
            ],
            "key_length": "81",
            "ref": [
              "s2cart.cscart_ab__category_banner_images_and_descr.category_banner_image_id",
              "const",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "index_condition": "(`s2cart`.`il`.`object_id` = `s2cart`.`cscart_ab__category_banner_images_and_descr`.`category_banner_image_id`)",
            "cost_info": {
              "read_cost": "0.25",
              "eval_cost": "0.10",
              "prefix_cost": "4.75",
              "data_read_per_join": "96"
            },
            "used_columns": [
              "pair_id",
              "object_id",
              "object_type",
              "type"
            ]
          }
        }
      ]
    }
  }
}