I'm running a very heavy query on MySQL which takes a few hours and would love to improve the process time. It looks like this:
insert into customers_input
select *
from
(
select *
from cust_a a join cut_b b on a.id=b.id
where a.date='2015-01-01' and a.date='2015-01-01'
) a left join
(
select *
from cust_c
) b on a.id=b.id;
cust_a - has 8,000,000 rows and only two different values for the date column, in addition a BTREE index on the id column
cust_b - has 600,000 rows and only two different values for the date column , in addition a BTREE index on the id column
cust_c - has 20,000 rows
My suspicion is that the problem is with the sub query (a) that joins tables cust_a and cust_b, simply because the process time has dramatically increased since I've added this sub query.
Any ideas or suggestions will be much appreciated.
Thanks in advance
EXPLAINor get an execution plan, put the results in the question as well. If you have no indexes, visit use-the-index-luke.com.