Skip to content

Commit a6f2293

Browse files
feat(speed-up): speed up ForecastAtTimestamp with distinct (#102)
Co-authored-by: devsjc <[email protected]>
1 parent 18b678c commit a6f2293

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

internal/server/postgres/sql/queries/predictions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ ORDER BY rp.target_time_utc ASC;
245245
* Predicted values are 16-bit integers, with 0 representing 0% and 30000 representing 100% of capacity.
246246
*/
247247
WITH relevant_forecasts AS (
248-
SELECT
248+
SELECT DISTINCT ON (f.geometry_uuid)
249249
f.forecast_uuid,
250250
f.geometry_uuid,
251251
f.source_type_id,
@@ -256,13 +256,13 @@ WITH relevant_forecasts AS (
256256
AND f.source_type_id = $1
257257
AND f.forecaster_id = $2
258258
AND f.target_period @> sqlc.arg(target_timestamp_utc)::TIMESTAMP
259+
ORDER BY f.geometry_uuid, f.init_time_utc
259260
),
260261
ranked_predictions AS (
261262
SELECT
262263
rf.forecast_uuid,
263264
rf.geometry_uuid,
264265
rf.source_type_id,
265-
rf.init_time_utc,
266266
pg.horizon_mins,
267267
pg.p50_sip,
268268
pg.target_time_utc,

0 commit comments

Comments
 (0)