Rule Definition
Having complex queries in Artifacts can cause performance problems.
Remediation
Review the query to reduce the number of involved Tables and/or Views.
Fixed Code Sample
The following procedures should be reviewed:
1. 5 Views are are joined:
DELIMITER //
CREATE OR REPLACE PROCEDURE SQLCPLEX001_13_DN_SHOW_8_Y() CONTAINS SQL
BEGIN
DECLARE SQLCPLEX001_var INTEGER;
SELECT STDTBL_COL_1_1 INTO SQLCPLEX001_var FROM SQLCPLEX001_8_DN_SHOW_3_Y, SQLCPLEX001_9_DN_SHOW_4_Y, SQLCPLEX001_10_DN_SHOW_5_Y, SQLCPLEX001_11_DN_SHOW_6_Y, SQLCPLEX001_12_DN_SHOW_7_Y;
END
//
DELIMITER ;
2. 5 Tables are joined, STD_TABLE_4 is joined 2 times :
DELIMITER //
CREATE OR REPLACE PROCEDURE SQLCPLEX001_16_DN_SHOW_12_X() CONTAINS SQL
BEGIN
DECLARE SQLCPLEX001_var VARCHAR(11);
SELECT DISTINCT STD_TABLE_1.COL1, STD_TABLE_2.COL1
FROM STD_TABLE_1, STD_TABLE_2
WHERE STD_TABLE_2.COL1 IN
(SELECT COL1
FROM STD_TABLE_3
WHERE COL2 = DATE '1999-04-27') AND
STD_TABLE_1.COL1 IN
(SELECT COL1
FROM STD_TABLE_4
WHERE STDTBL_COL1_1 = DATE '1999-04-27') AND
STD_TABLE_2.COL1 IN
(SELECT COL1
FROM STD_TABLE_4
WHERE STDTBL_COL1_1 = DATE '1999-04-28') ;
END
//
DELIMITER ;
3. 5 Tables are joined :
DELIMITER //
CREATE OR REPLACE PROCEDURE SQLCPLEX001_15_SHOW_11_X() CONTAINS SQL
BEGIN
DECLARE SQLCPLEX001_var VARCHAR(11);
SELECT STD_TABLE_4.STDTBL_COL1_1, STD_TABLE_1.COL1
FROM STD_TABLE_1
INNER JOIN STD_TABLE_2
ON STD_TABLE_2.COL1 = STD_TABLE_1.COL1
INNER JOIN STD_TABLE_3
ON STD_TABLE_3.COL1 = STD_TABLE_2.COL1
INNER JOIN STD_TABLE_4
ON STD_TABLE_4.COL1 = STD_TABLE_3.COL1
INNER JOIN STD_TABLE_5
ON STD_TABLE_5.COL1 = STD_TABLE_4.COL1;
END
//
DELIMITER ;
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.