Hello! I have the following code:
$key_cache = 'cache_banners_tpl_'. $idpl; $dateNow = date(MYSQL_DATE_FORMAT); $dateTimeNow = date("H:i:s"); if(($banners = $this->app->cache5min->get($key_cache)) === NULL) { $find_items = array(); $banners = $this->app->db->fetchAll("SELECT b.id,b.active,b.richmedia,b.rich_position,b.ip_limit,b.cookie_limit,b.cookie_interval,b.day_limit,b.limit_interval,b.frequency, b.close_btn, b.use_geo, bpl.s_x, bpl.s_y FROM bs_items_places AS bp LEFT JOIN bs_items AS b ON b.id = bp.item_id LEFT JOIN bs_places AS bpl ON bpl.id = bp.place_id WHERE b.active = 1 AND b.date_start < '".$dateNow."' AND b.date_stop > '".$dateNow."' AND bpl.active = 1 AND bp.place_id = {$idpl} AND (IF((time_from!='00:00:00' AND time_to!='00:00:00'),(time_from<='".$dateTimeNow."' AND time_to>='".$dateTimeNow."'),1)) GROUP BY b.id ORDER BY b.frequency DESC, b.day_limit DESC "); foreach($banners AS $bnr) { $find_items[$bnr['id']] = $bnr; } $banners = $find_items; $this->app->cache5min->save($key_cache,$banners); } EXPLAIN query:
explain SELECT `bs_items_ip`.`id`, `bs_items_ip`.`item_id`, `bs_items_ip`.`place_id`, `bs_items_ip`.`date_show`, `bs_items_ip`.`ip`, `bs_items_ip`.`shows` FROM `bs_items_ip` WHERE `bs_items_ip`.`item_id` = 146 AND `bs_items_ip`.`ip` = '94.100.184.101' AND `bs_items_ip`.`date_show` = '2017-05-29' LIMIT 1; +----+-------------+-------------+------+---------------+---------+---------+-------+--------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+------+---------------+---------+---------+-------+--------+-------------+ | 1 | SIMPLE | bs_items_ip | ref | item_id | item_id | 5 | const | 580178 | Using where | +----+-------------+-------------+------+---------------+---------+---------+-------+--------+-------------+ 1 row in set (0.00 sec) it loads me very much the processor, is it possible to somehow optimize it? So that the processor does not load, because of this, the site does not work well. As soon as I remove and comment on this code, the load immediately drops.
EXPLAIN ТУТ_ТВОЙ_ЗАПРОС..... and see the results ... secondly, you need to see if you have indexes in the tables - Alexey Shimanskytime_fromtime instead of zeros can not be done onNULL? - teran