UltraSmooth
Programmer
I'm trying to do a join between two tables, one with no more than a couple of hundred records and one with about 4 million. My issue is that mysql is ignoring my index on the large table thus making the query extremely slow.
Here's my query,
select fiscalyear,fiscalweek,his_key,his_loctn,his_salunit,his_salretl,his_salcost
from syinvhis
join weekly_periods
on his_tdate=clarion_date and weekly_periods.fiscalyear=2009 and weekly_periods.fiscalweek=1
and his_type='DC' and his_loctn in ('01','03','04','05') and his_period='W' and his_service='R';
- weekly_periods has a PRIMARY_KEY on the column clarion_date
- syinvhis has an index over the columns his_tdate,his_type,his_loctn,his_period,his_service,his_key
I have two similar tables to weekly_periods - monthly_periods and yearly_periods and these have PRIMARY_KEYS on clarion_date. When I do the same query as above but instead join to one of these other tables (with syinvhis) they index is used properly on the date column.
Any ideas what is going on here?
Also, what is the difference in specifiying selection conditions in the ON section of a JOIN as opposed to the WHERE section? My best guess is that the ON section limits when the records are actually joining and the WHERE filters out records after the join has taken place. Is there any difference in the effect it has on what indexes are chosen?
Thanks! This forum has been a fabulous resource.
Here's my query,
select fiscalyear,fiscalweek,his_key,his_loctn,his_salunit,his_salretl,his_salcost
from syinvhis
join weekly_periods
on his_tdate=clarion_date and weekly_periods.fiscalyear=2009 and weekly_periods.fiscalweek=1
and his_type='DC' and his_loctn in ('01','03','04','05') and his_period='W' and his_service='R';
- weekly_periods has a PRIMARY_KEY on the column clarion_date
- syinvhis has an index over the columns his_tdate,his_type,his_loctn,his_period,his_service,his_key
I have two similar tables to weekly_periods - monthly_periods and yearly_periods and these have PRIMARY_KEYS on clarion_date. When I do the same query as above but instead join to one of these other tables (with syinvhis) they index is used properly on the date column.
Any ideas what is going on here?
Also, what is the difference in specifiying selection conditions in the ON section of a JOIN as opposed to the WHERE section? My best guess is that the ON section limits when the records are actually joining and the WHERE filters out records after the join has taken place. Is there any difference in the effect it has on what indexes are chosen?
Thanks! This forum has been a fabulous resource.