CRITICAL
Rule Definition
Programs containing queries on a large number of tables can cause performance problems.
Remediation
Try to reduce the complexity of queries or the number of complex queries.
Violation Code Sample
SELECT ed.emp_id, ed.emp_name , ed.emp_pf, emd.designation_name, te.pfacc1, te.pfacc2, temp. pf_percent, temp.pf_max
FROM dbo.emp_details AS ed
LEFT JOIN dbo.emp_designation AS emd ON emd.designation_id = ed.emp_designation
LEFT JOIN dbo.tbl_empcontribution AS te ON te.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction AS temp ON temp.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction1 AS temp ON temp.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction1 AS temp ON temp.eid = ed.emp_id
Where ed.team = 'CoE';
Fixed Code Sample
Consider using CTEs to reduce complexity
With T (emp_id, emp_name , emp_pf, designation_name, pfacc1, pfacc2, pf_percent, pf_max)
AS (
SELECT ed.emp_id, ed.emp_name , ed.emp_pf, emd.designation_name, te.pfacc1, te.pfacc2, temp. pf_percent, temp.pf_max
FROM dbo.emp_details AS ed
LEFT JOIN dbo.emp_designation AS emd ON emd.designation_id = ed.emp_designation
LEFT JOIN dbo.tbl_empcontribution AS te ON te.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction AS temp ON temp.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction1 AS temp ON temp.eid = ed.emp_id
LEFT JOIN dbo.tbl_empdeduction1 AS temp ON temp.eid = ed.emp_id
)
Select emp_id, emp_name , emp_pf, designation_name, pfacc1, pfacc2, pf_percent, pf_max
from T where e.team = 'CoE';
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.