Hi,
My first post here so be gentle confused:
I have a query which joins to a tmp table BUT before I even go there I ran the EXPLAIN on the query that creates the tmp table & found it isn’t using any indexes??
The code is
CREATE TEMPORARY TABLE tmpSELECT EDPG_SchAttYearCode as School_Year, EDPG_SchAttTermCode as School_Term,EDPG_L0Code as Ethnicity, EDPG_YearCode as Year_Code, EDPG_Gender as Gender, COUNT(DISTINCT(EDPG_UPN)) AS Total_Pupils FROM EDPG_PupilGrouped LEFT JOIN Lookup_PcodeGeo ON EDPG_Postcode = LKPC_Postcode WHERE LKPC_District=“Sandwell” GROUP By School_Year, School_Term, Ethnicity, Year_Code , Gender;
I have an index (EDPG_Idx1) on the table edpg_pupilgrouped using the columns in this order;
EDPG_SchAttYearCode (Cardinality:1)EDPG_SchAttTermCode (Cardinality:5)EDPG_L0Code as Ethnicity (Cardinality:2)EDPG_YearCode as Year_Code (Cardinality:17)EDPG_Gender as Gender (Cardinality:2)
When I run the EXPLAIN it returns
id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE EDPG_PupilGrouped ALL EDPG_Postcode NULL NULL NULL 243425 Using filesort1 SIMPLE Lookup_PcodeGeo eq_ref PRIMARY,LKPC_District,LKPC_Postcode PRIMARY 8 development.EDPG_PupilGrouped.EDPG_Postcode 1 Using where
Can anybody help me or explain how indexes work I’m pulling my hair out mad: