mardi 27 janvier 2015

query explain saidd row is a few but it took an hour to load


i have a query down here



select
if (
month(td.date) = month('2011-01-01') and year(td.date) = year('2011-01-01') and month(td.date) = month('2011-01-02') and year(td.date) = year('2011-01-02')
,
timestampDIFF(DAY,'2011-01-01','2011-01-02')+1
,
case when month(td.date) = month('2011-01-02') and year(td.date) = year('2011-01-02') then
day('2011-01-02')
when month(td.date) = month('2011-01-01') and year(td.date) = year('2011-01-01') then
timestampDIFF(DAY,'2011-01-01',last_day('2011-01-01'))+1
else

DAY(LAST_DAY(td.date))
end
) as difdate,
all_OD.Billing_models_Code , all_OD.Entrance_number, all_OD.Exit_number , all_OD.Rates_distance , all_OD.Entrance_Name, all_OD.Exit_Name ,
td.*,

cast(concat(year(td.Date),'年',month(td.Date),'月 月平均') as char) as jdateTime,
-- (c.normalCar + c.bigCar) as correctionNow,
-- (t.normalCarTotal + t.bigCarTotal) as totalNow,
-- (c2.normalCar + c2.bigCar) as correctionYesterday,
-- (t2.normalCarTotal + t2.bigCarTotal) as totalYesterday,
td.DATE AS realDate
-- ifnull((c.normalCar + c.bigCar)/ (t.normalCarTotal + t.bigCarTotal),0) as ratioNow,
-- ifnull((c2.normalCar + c2.bigCar) / (t2.normalCarTotal + t2.bigCarTotal),0) as ratioYesterday
from table_data_cache as td
-- left outer join total_each_day as t on t.date = td.date
-- left outer join total_each_day as t2 on t2.date = date_sub(td.date , interval 1 day)
-- left outer join correction as c on c.date = td.date
-- left outer join correction as c2 on c2.date = date_sub(td.date , interval 1 day)
left outer join holiday as hol on hol.date = td.date
left outer join all_OD as all_OD on all_OD.ODID = td.odid and all_OD.Billing_models_Code = td.carType
where all_OD.Entrance_Number in (3) and all_OD.Exit_Number in (2,5,9,15,17,21,25,29,33,37,40,41,45,49,53,57,61,65,69,73,75,89,93,97,105,109,111,121,128,129,131,133,135,141,145,149,153,157,161,165,171,173,185,189,193,196,200,201,204,205,209,213,217,221,225,229,233,237,241,245,253,257,261,265,269,273,277,287,291,295,299,303,307,311,315,319,321,328,329,335,338,343,347,353,356,358,360,362,364,365,369,372,383,385,390,393,397,401,409,413,417,421,423,427,429,441,463,467,471,475,479,483,487,491,495,499,503,504,507,539,541,547,549,553,571,575,579,583,593,597,599,603,607,611,615,619,623,627,635,639,643,647,651,655,659,663,703,707,713,715,748,749,759,763,767,771,775,779,783,787,791,795,799,800,803,811,835,839,841,847,848,849,851,855,863,867,871,875,877,878,879,883,887,889,891,897,900,901,912,919,925,926,932,937,939) and td.date >= date('2011-01-01') and td.date <= date('2011-01-02') and td.carType = 2 AND ( DAYOFWEEK(td.date) >= 2 AND DAYOFWEEK(td.date) <= 6 ) AND td.date <> date('2011-1-1') and hol.date is null


but when i add explain in front of that query



explain extended
select
if (
month(td.date) = month('2011-01-01') and year(td.date) = year('2011-01-01') and month(td.date) = month('2011-01-02') and year(td.date) = year('2011-01-02')
,
timestampDIFF(DAY,'2011-01-01','2011-01-02')+1
,
case when month(td.date) = month('2011-01-02') and year(td.date) = year('2011-01-02') then
day('2011-01-02')
when month(td.date) = month('2011-01-01') and year(td.date) = year('2011-01-01') then
timestampDIFF(DAY,'2011-01-01',last_day('2011-01-01'))+1
else

DAY(LAST_DAY(td.date))
end
) as difdate,
all_OD.Billing_models_Code , all_OD.Entrance_number, all_OD.Exit_number , all_OD.Rates_distance , all_OD.Entrance_Name, all_OD.Exit_Name ,
td.*,

cast(concat(year(td.Date),'年',month(td.Date),'月 月平均') as char) as jdateTime,
-- (c.normalCar + c.bigCar) as correctionNow,
-- (t.normalCarTotal + t.bigCarTotal) as totalNow,
-- (c2.normalCar + c2.bigCar) as correctionYesterday,
-- (t2.normalCarTotal + t2.bigCarTotal) as totalYesterday,
td.DATE AS realDate
-- ifnull((c.normalCar + c.bigCar)/ (t.normalCarTotal + t.bigCarTotal),0) as ratioNow,
-- ifnull((c2.normalCar + c2.bigCar) / (t2.normalCarTotal + t2.bigCarTotal),0) as ratioYesterday
from table_data_cache as td
-- left outer join total_each_day as t on t.date = td.date
-- left outer join total_each_day as t2 on t2.date = date_sub(td.date , interval 1 day)
-- left outer join correction as c on c.date = td.date
-- left outer join correction as c2 on c2.date = date_sub(td.date , interval 1 day)
left outer join holiday as hol on hol.date = td.date
left outer join all_OD as all_OD on all_OD.ODID = td.odid and all_OD.Billing_models_Code = td.carType
where all_OD.Entrance_Number in (3) and all_OD.Exit_Number in (2,5,9,15,17,21,25,29,33,37,40,41,45,49,53,57,61,65,69,73,75,89,93,97,105,109,111,121,128,129,131,133,135,141,145,149,153,157,161,165,171,173,185,189,193,196,200,201,204,205,209,213,217,221,225,229,233,237,241,245,253,257,261,265,269,273,277,287,291,295,299,303,307,311,315,319,321,328,329,335,338,343,347,353,356,358,360,362,364,365,369,372,383,385,390,393,397,401,409,413,417,421,423,427,429,441,463,467,471,475,479,483,487,491,495,499,503,504,507,539,541,547,549,553,571,575,579,583,593,597,599,603,607,611,615,619,623,627,635,639,643,647,651,655,659,663,703,707,713,715,748,749,759,763,767,771,775,779,783,787,791,795,799,800,803,811,835,839,841,847,848,849,851,855,863,867,871,875,877,878,879,883,887,889,891,897,900,901,912,919,925,926,932,937,939) and td.date >= date('2011-01-01') and td.date <= date('2011-01-02') and td.carType = 2 AND ( DAYOFWEEK(td.date) >= 2 AND DAYOFWEEK(td.date) <= 6 ) AND td.date <> date('2011-1-1') and hol.date is null


it shows that query only read 100 enter image description here


but why it took 1 hour to fetch?





Aucun commentaire:

Enregistrer un commentaire