SELECT 
  cscart_banners.banner_id, 
  cscart_banners.type, 
  cscart_banners.target, 
  cscart_banners.status, 
  cscart_banners.timestamp, 
  cscart_banner_descriptions.banner, 
  cscart_banner_descriptions.description, 
  cscart_banner_descriptions.url, 
  cscart_banner_images.banner_image_id 
FROM 
  cscart_banners 
  LEFT JOIN cscart_banner_descriptions ON cscart_banner_descriptions.banner_id = cscart_banners.banner_id 
  AND cscart_banner_descriptions.lang_code = 'en' 
  LEFT JOIN cscart_banner_images ON cscart_banner_images.banner_id = cscart_banners.banner_id 
  AND cscart_banner_images.lang_code = 'en' 
WHERE 
  1 
  AND (
    cscart_banners.type != 'G' 
    OR cscart_banner_images.banner_image_id IS NOT NULL
  ) 
  AND cscart_banners.banner_id IN (36, 37, 38, 39) 
  AND cscart_banners.status = 'A' 
  AND IF(
    cscart_banners.from_date, cscart_banners.from_date <= 1732141739, 
    1
  ) 
  AND IF(
    cscart_banners.to_date, cscart_banners.to_date >= 1732141739, 
    1
  ) 
  AND (
    cscart_banners.usergroup_ids = '' 
    OR FIND_IN_SET(0, cscart_banners.usergroup_ids) 
    OR FIND_IN_SET(1, cscart_banners.usergroup_ids)
  ) 
  AND IF (
    cscart_banners.type not like 'abt__ut2', 
    'available', 
    IF (
      cscart_banners.type like 'abt__ut2' 
      AND (
        cscart_banners.abt__ut2_use_avail_period = 'N' 
        OR (
          cscart_banners.abt__ut2_use_avail_period = 'Y' 
          AND (
            cscart_banners.abt__ut2_avail_from = 0 
            OR cscart_banners.abt__ut2_avail_from <= 1732141739
          ) 
          AND (
            cscart_banners.abt__ut2_avail_till = 0 
            OR cscart_banners.abt__ut2_avail_till >= 1732141739
          )
        )
      ), 
      'available', 
      'not available'
    )
  ) = 'available' 
  AND (
    cscart_banners.abt__ut2_usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_banners.abt__ut2_usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_banners.abt__ut2_usergroup_ids
    )
  ) 
ORDER BY 
  cscart_banner_descriptions.banner asc

Query time 0.00387

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "9.52"
    },
    "ordering_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "3.95"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_banners",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "status"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "banner_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 4,
            "rows_produced_per_join": 3,
            "filtered": "98.75",
            "index_condition": "(`s2cart`.`cscart_banners`.`banner_id` in (36,37,38,39))",
            "cost_info": {
              "read_cost": "2.41",
              "eval_cost": "0.40",
              "prefix_cost": "2.81",
              "data_read_per_join": "27K"
            },
            "used_columns": [
              "banner_id",
              "status",
              "type",
              "target",
              "timestamp",
              "abt__ut2_use_avail_period",
              "abt__ut2_avail_from",
              "abt__ut2_avail_till",
              "from_date",
              "to_date",
              "usergroup_ids",
              "abt__ut2_usergroup_ids"
            ],
            "attached_condition": "((`s2cart`.`cscart_banners`.`status` = 'A') and (0 <> if(`s2cart`.`cscart_banners`.`from_date`,(`s2cart`.`cscart_banners`.`from_date` <= 1732141739),1)) and (0 <> if(`s2cart`.`cscart_banners`.`to_date`,(`s2cart`.`cscart_banners`.`to_date` >= 1732141739),1)) and ((`s2cart`.`cscart_banners`.`usergroup_ids` = '') or (0 <> find_in_set(0,`s2cart`.`cscart_banners`.`usergroup_ids`)) or (0 <> find_in_set(1,`s2cart`.`cscart_banners`.`usergroup_ids`))) and (if((not((`s2cart`.`cscart_banners`.`type` like 'abt__ut2'))),'available',if(((`s2cart`.`cscart_banners`.`type` like 'abt__ut2') and ((`s2cart`.`cscart_banners`.`abt__ut2_use_avail_period` = 'N') or ((`s2cart`.`cscart_banners`.`abt__ut2_use_avail_period` = 'Y') and ((`s2cart`.`cscart_banners`.`abt__ut2_avail_from` = 0) or (`s2cart`.`cscart_banners`.`abt__ut2_avail_from` <= 1732141739)) and ((`s2cart`.`cscart_banners`.`abt__ut2_avail_till` = 0) or (`s2cart`.`cscart_banners`.`abt__ut2_avail_till` >= 1732141739))))),'available','not available')) = 'available') and ((`s2cart`.`cscart_banners`.`abt__ut2_usergroup_ids` = '') or (0 <> find_in_set(0,`s2cart`.`cscart_banners`.`abt__ut2_usergroup_ids`)) or (0 <> find_in_set(1,`s2cart`.`cscart_banners`.`abt__ut2_usergroup_ids`))))"
          }
        },
        {
          "table": {
            "table_name": "cscart_banner_descriptions",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "banner_id",
              "lang_code"
            ],
            "key_length": "9",
            "ref": [
              "s2cart.cscart_banners.banner_id",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 3,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.99",
              "eval_cost": "0.40",
              "prefix_cost": "4.19",
              "data_read_per_join": "19K"
            },
            "used_columns": [
              "banner_id",
              "banner",
              "url",
              "description",
              "lang_code"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_banner_images",
            "access_type": "eq_ref",
            "possible_keys": [
              "banner"
            ],
            "key": "banner",
            "used_key_parts": [
              "banner_id",
              "lang_code"
            ],
            "key_length": "9",
            "ref": [
              "s2cart.cscart_banners.banner_id",
              "const"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 3,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.99",
              "eval_cost": "0.40",
              "prefix_cost": "5.58",
              "data_read_per_join": "63"
            },
            "used_columns": [
              "banner_image_id",
              "banner_id",
              "lang_code"
            ],
            "attached_condition": "<if>(found_match(cscart_banner_images), ((`s2cart`.`cscart_banners`.`type` <> 'G') or (`s2cart`.`cscart_banner_images`.`banner_image_id` is not null)), true)"
          }
        }
      ]
    }
  }
}