As know IN clause is one of the performance decrease operator when operating huge volume of data. Let see how to avoid IN clause and what could be alternative way to accomplish same functionality.
This query contains IN clause and taking too much time
SELECT column_list FROM TABLE1
WHERE
Column_name in (SELECT column_name FROM TABLE2 )
To improve the performance of above query, could move the sub query statement into CTE ( Common Table Expression) and join with main query.
WITH CTE AS
(SELECT column_name FROM TABLE2 )
SELECT column_list FROM TABLE1
INNER JOIN CTE
ON TABLE1.column_name = CTE.column_name
That's it, The second query results tremendous improvement, when handling huge volume of data.
Any other questions to improve the DB2 performances, please feel free to write up
This query contains IN clause and taking too much time
SELECT column_list FROM TABLE1
WHERE
Column_name in (SELECT column_name FROM TABLE2 )
To improve the performance of above query, could move the sub query statement into CTE ( Common Table Expression) and join with main query.
WITH CTE AS
(SELECT column_name FROM TABLE2 )
SELECT column_list FROM TABLE1
INNER JOIN CTE
ON TABLE1.column_name = CTE.column_name
That's it, The second query results tremendous improvement, when handling huge volume of data.
Any other questions to improve the DB2 performances, please feel free to write up
Comments
Post a Comment