mysql: slow query on indexed field -


the orders table has 2m records. there ~900k unique ship-to-ids.

there index on ship_to_id ( field isint(8)).

the query below takes 10mn complete. i've run processlist has command = query , state = sending data.

when run explain, existing index used, , possible_keys null.

is there should speed query up? thanks.

select    ship_to_id customer_id  orders  group ship_to_id  having sum( price_after_discount ) > 0 

does not have useful index. try adding index on price_after_discount, , add condition this:

where price_after_discount > 0 

to minimize number of rows need sum can discard 0.

also try running "top" command , @ io "wait" column while query running. if high, means query causes lot of disk i/o. can increase various memory buffers if have ram speed (if you're using innodb) or myisam done through filesystem cacheing. restarting server flush these caches.

if not have enough ram (which shouldn't need 2m records) consider partitioning scheme against maybe ship-to-ids column (if version of mysql supports it).


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -