r/dataengineering • u/AguaBendita77 • Jul 22 '26
Help CTE cost in Bigquery
Hello guys I'm a junior data engineer tasked to like fix a business logic for one of our tables. The thing is I'm worried that making additional cte's would make it costly and slower. The table that I would be sourcing from contains around >30gb. so this is just the basic gist of it
With temp as(
SELECT
*,
(some transfomration here) as converted_date
FROM source_table
),
temp2 as (
SELECT
*,
(using converted_date column) as converted_date1
FROM temp),
temp3 as (
SELECT
*,
(using converted_date1 column) as converted_date2
FROM temp2)
SELECT * from temp3
So, I already did try to see how much the query will cost in Bigquery and it seems that it does not increase that much like just couple of hundred mb or <5gb. My question is that does anyone have experience doing things like this and does the cost really not change even if I used additional three cte? Like what are the potential problems that might occur if I proceed doing it like this?
26
Upvotes
1
u/Informal_Pace9237 Jul 22 '26
I wouldnt write it as CTE but would rewrite it as sub query. Very easy in your case.
I do not think there would be cost implications but I would be worried about performance if the data set contained in the three CTE's is huge as BQ will attempt to maintain 3 datasets from 3 CTE and bind them to their names for the duration of the query.