mysql - Query tuning Optimizing -
below query. how query can optimized?
select representative.rep_name rname, sum(areawise_temp.quantity*product.ptr) totptr, sum(areawise_temp.quantity*product.pts) totpts areawise_temp, product, representative (areawise_temp.bill_date between '2015/04/01' , '2015/04/30') , areawise_temp.our_cust_id <> '' , areawise_temp.our_product_id <> '' , areawise_temp.pincode in ( select pincode_list.pincode pincode_list pincode_list.pin_id in ( select rep_area.pin_id rep_area rep_id in ( select id representative ) ) group pincode_list.pincode ) , areawise_temp.our_product_id = product.id
the coding pattern in ( select ... ) poorly optimized. change join.
for example, innermost part can be
select ra.pin_id rep_area ra join representative r on r.id = ra.rep_id also make sure have necessary indexes. let's see show create table you. above snippet, representative has primary key(id)?
Comments
Post a Comment