Assume you are creating some query using tables A and B, which are inner joined on COL_ID:
SELECT A.*, B.*
FROM A INNER JOIN B ON (A.COL_ID = B.COL_ID);
Let's say you want to transform a lot of the columns from table B, and as the query is going to have lots and lots of columns, you decide to move the transformation logic into a CTE, i.e:
WITH cte_b AS (
SELECT (CAST(B.COL1 AS INT) AS COL1_INT,
.....
FROM B
)
SELECT A.*, cte_b.*
FROM A INNER JOIN cte_b ON (A.COL_ID = cte_b.COL_ID);
As opposed to including any transformations in the main query:
SELECT A.*,
B.*,
(CAST(B.COL1 AS INT) AS COL1_INT,
.....
FROM A INNER JOIN B ON (A.COL_ID = B.COL_ID);
Between the 2 options - is there a significant peformance difference?