0

I have tried to fetch the data from view table .I have executed select query in phpmyadmin .It takes 5.2875 seconds. But normal table takes only 0.0300 seconds. Query :

SELECT line FROM `summary_view` WHERE date='2022-02-25'  

CREATE VIEW summary_view AS select adh.id AS id, adh.line AS line, fam.area AS area, fam.sub_area AS sub_area, fam.family AS family, pro.produced AS produced, pro.service AS service, round(((testdb.down * 60) / adh.takt_time),0) AS units_lost, round(((((adh.worked_time * 60) - adh.break_time) * 60) / adh.takt_time),0) AS oa_capacity, round(((((adh.plan_time * 60) - adh.break_time) * 60) / adh.takt_time),0) AS ay_capacity, testdb.machines AS machines, testdb.manpower AS manpower, testdb.material AS material, testdb.methods AS methods, testdb.misc AS misc, testdb.down AS down, round((((pro.produced + pro.service) * adh.takt_time) / 60),0) AS uptime, adh.break_time AS break_time, round(((adh.worked_time * 60) - (((((pro.produced + pro.service) * adh.takt_time) / 60) + testdb.down) + adh.break_time)),0) AS minute_error, round((adh.worked_time * 60),0) AS working_time, round(((adh.worked_time * 60) - adh.break_time),0) AS worked_time, round(((adh.plan_time * 60) - adh.break_time),0) AS plan_time, round(adh.takt_time,0) AS takt_time, NULL AS headcount, rep.nff AS nff, rep.dpu AS dpu, round(((((pro.produced + pro.service) * adh.takt_time) / 60) / ((adh.worked_time * 60) - adh.break_time)),4) AS oa, round(((((pro.produced + pro.service) * adh.takt_time) / 60) / ((adh.plan_time * 60) - adh.break_time)),4) AS ay, adh.shift AS shift, GET_MONTH(adh.date) AS month, GET_WEEK(adh.date) AS week, adh.date AS date, adh.skey AS skey from ( ( ( ( adhoc adh left join ( select sum(if((down.category = 'Machines'),down.duration,NULL)) AS machines, sum(if((down.category = 'Manpower'),down.duration,NULL)) AS manpower, sum(if((down.category = 'Material'),down.duration,NULL)) AS material, sum(if((down.category = 'Methods'),down.duration,NULL)) AS methods, sum(if((down.category = 'Misc'),down.duration,NULL)) AS misc, sum(down.duration) AS down, down.skey AS skey from (down join family on((down.line = family.line))) where ((down.reason <> 'Scheduled Shutdown') and (family.area in ('Indoor','Outdoor','Specialty'))) group by down.skey ) testdb on((adh.skey = testdb.skey)) ) left join ( select count(if((prod.repair_flag <> 'S'),1,NULL)) AS produced, count(if((prod.repair_flag = 'S'),1,NULL)) AS service, prod.skey AS skey from (prod join family on((prod.line = family.line))) group by prod.skey ) pro on((adh.skey = pro.skey)) ) left join ( select count(if((repair.level_one = 'No Fault Found'),1,NULL)) AS nff, count(if(((repair.level_one <> 'No Fault Found') and (repair.level_two <> 'Reclaim Refrigerant')),1,NULL)) AS dpu, repair.skey AS skey from repair group by repair.skey ) rep on((adh.skey = rep.skey)) ) join family fam on((adh.line = fam.line)) ) where (adh.area = 'Assembly') ;

How to reduce the query execution time in view table ? Is there any way to reduce the execution time without adding index ?

4
  • 1
    This is heavily dependent on the view definition and on the presence of indexes in the underlying tables. Please include the view definition. Remember that views are just syntactic sugar for your queries; they don't hold data. Jun 28, 2022 at 16:14
  • First of all, does the table adh have an index on tha column date? It could help the query. Jun 28, 2022 at 17:16
  • Also, down should have an index on (skey, line); prod shoud have the same index. repair should have an index on skey; family should have an index on line. Jun 28, 2022 at 17:19
  • Is there any way without adding index ?
    – REVATHI
    Jun 29, 2022 at 11:37

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.