I have the following query:
select count(inspection_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and inspection_result= 1 and part_type = "39000048" and location = "1" union all
select count(inspection_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and inspection_result= 0 and part_type = "39000048" and location = "1" union all select count(defect_1_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_1_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_2_value_1_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_2_value_1_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_2_value_2_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_2_value_2_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_3_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_3_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_4_value_1_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_4_value_1_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_4_value_2_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_4_value_2_result= 0 and part_type = "39000048" and location = "1" union all
select count(defect_5_result) from copygtron where (inspection_time between "2015-07-15" and "2015-07-21") and defect_5_result= 0 and part_type = "39000048" and location = "1"...
I have to execute this query for 3, 4 , 5.. or 10 months or weeks according to user input. There are according 1.1 million data and incoming data will be 72 000 per hour and for executing this query it takes around 6 seconds, which is not good . It has to be reduced to 20 millisecond. Partitioning has been done for 12 months and inspection_time and defects columns are reduced.
Can anyone help me?