@@ -144,19 +144,23 @@ def _get_core_hierarchy_query(
144144 Input ,
145145 and_ (
146146 Output .dataset_id == Input .dataset_id ,
147- Output .created_at >= Input .created_at ,
148147 Output .job_id != Input .job_id ,
149148 ),
150149 )
151150 .where (
152151 Input .created_at >= bindparam ("since" ),
152+ Output .created_at >= bindparam ("since" ),
153+ Output .created_at >= Input .created_at ,
153154 or_ (
154155 bindparam ("until" , type_ = DateTime (timezone = True )).is_ (None ),
155- Output .created_at <= bindparam ("until" ),
156+ and_ (
157+ Input .created_at <= bindparam ("until" ),
158+ Output .created_at <= bindparam ("until" ),
159+ ),
156160 ),
157161 )
158162 )
159- return query .cte ("jobs_hierarchy_core_query" )
163+ return query .cte ("jobs_hierarchy_core_query" ). prefix_with ( "NOT MATERIALIZED" , dialect = "postgresql" )
160164
161165 def _get_upstream_hierarchy_query (
162166 self ,
@@ -176,7 +180,7 @@ def _get_upstream_hierarchy_query(
176180 core_query .c .from_job_id .label ("from_job_id" ),
177181 core_query .c .to_job_id .label ("to_job_id" ),
178182 core_query .c .type .label ("type" ),
179- (base_query_cte .c .depth + 1 ).label ("depth" ),
183+ (base_query_cte .c .depth + literal ( 1 ) ).label ("depth" ),
180184 )
181185 .join (
182186 core_query ,
@@ -207,7 +211,7 @@ def _get_downstream_hierarchy_query(
207211 core_query .c .from_job_id .label ("from_job_id" ),
208212 core_query .c .to_job_id .label ("to_job_id" ),
209213 core_query .c .type .label ("type" ),
210- (base_part_cte .c .depth + 1 ).label ("depth" ),
214+ (base_part_cte .c .depth + literal ( 1 ) ).label ("depth" ),
211215 )
212216 .join (
213217 core_query ,
0 commit comments