I have stored all the Permutations and combinations of all the attributes necessary to create a product based on color,weight and quality and stored it in attribute table.
In program I loop on the data from this table and create Select sql to query another table which contains Product Price based on the attributes and I store it in third table.
I have suppose 7000 records in attribute table and 2 Lakh records in Price table. So the program loops to 7000 records and Each select SQL queries 2Lakh records.
Select SQL contains Multiple Where Clauses and a Order by on Price to get the lowest price.
My question is how can I reduce the query execution time.
Example :-
Attribute table
sno color Quality Weight
1 blue Good 3kg
2 red Fair 1kg
3 Yellow Excellent 1.5Kg
Price table
sno color Quality Weight(in kgs) Market Price Our Price
1 sky blue Good 4 $400 $360
2 orange red Excellent 2 $500 $450
Price table For Red I store - Crimson Red,Orange Red etc.
But Attribute I have Red bcoz Red is Prime color and in market u don't get perfect Red. So I give Product close to Red and cheaper in that Red group.
select * from tbl_price
where color IN {Array [tbl data Entry i.e. RED ] gives-> ( "Crimson Red", "Orange Red","Carrot Red" )}
AND Quality IN {Array [tbl data Entry i.e. Good ] gives-> ("Above Average","Medium","Not Bad" )}
AND Weight >= {tbl Entry of Weight}
Order by OurPrice ASC
LIMIT 1,1;