# HG changeset patch # User Tom Gottfried # Date 1571838787 -7200 # Node ID 3b3cf2083730a139304b9892154c07810fd4d1ea # Parent 1fef9d8e7eb20f9e469eff668382ac676d8453b4 Avoid type cast that prevents index usage Casting to timestamp instead of timestamptz prevented usage of an index on measure_date. To be sure, also pass the location code as isrs instead of type record. diff -r 1fef9d8e7eb2 -r 3b3cf2083730 pkg/controllers/gauges.go --- a/pkg/controllers/gauges.go Wed Oct 23 15:23:52 2019 +0200 +++ b/pkg/controllers/gauges.go Wed Oct 23 15:53:07 2019 +0200 @@ -60,16 +60,9 @@ water_level FROM waterway.gauge_predictions ) AS gmp -WHERE - location = ( - $1::char(2), - $2::char(3), - $3::char(5), - $4::char(5), - $5::int - ) AND - measure_date BETWEEN - $6::timestamp - '72hours'::interval AND $6::timestamp +WHERE location = ($1, $2, $3, $4, $5)::isrs + AND measure_date BETWEEN + $6::timestamptz - '72hours'::interval AND $6::timestamptz ORDER BY measure_date, date_issue ` selectWaterlevelsSQL = `