mysql - slow query when I used ORDER BY -
when trying query order works slow. takes 20-30seconds. without order 1 second. mysql version 5.5
select distinct(product.id), product.position, product.condition, product.city_id, product.price, product.company_name, product.timestamp_update, product.company_id, company.company_type, company.image company_image, city.name city_name `product_to_tag` `v2t` join `product` on product.id = v2t.product_id join `product_to_city` `vtc` on product.id = vtc.product_id join `city` `c` on c.id = vtc.city_id left join `city` `city` on city.id=product.city_id left join `company` on company.id=product.company_id ((`product`.`publish` = 1)) , (product.id != 5016460) , (c.id = 99 or c.parent_id = 99) , ((`v2t`.`tag_id` in (65, 181, 228, 1135))) order `product`.`timestamp_update` desc limit 30;
is there indexes on order column?
it because if query not contain order return data in whatever order found. quickest option. whereas, when include order clause, database has build list of rows in correct order , return data in order.
this more time consuming on database , why takes longer. if have indexes on ordered column, other suggestion @ order of joining tables e.g joining smallest table first.
Comments
Post a Comment