Fix Timeseries/recent endpoint speed - #1183
Conversation
… timeseries-endpoint-speed
… still updating individual pieces
MikeNeilson
left a comment
There was a problem hiding this comment.
Looks reasonable. Definitely need to chew on it a bit. Fairly complex query, though I doubt unnecessarily so.
| .from(baseIds); | ||
|
|
||
| // references to appropriate year tables | ||
| Table<?> AT_TSV_2023_TABLE = table(name("AT_TSV_2023")); |
There was a problem hiding this comment.
These should be AT_TSV_PREV_YEAR and AT_TSV_CURRENT_YEAR and calculated at usage. Otherwise we'll have to remember to update them constantly.
There was a problem hiding this comment.
Yup you're correct. I just had those as place holders for now.
|
Newly fixed proposed DB query:
with
"base_ids" as (
select distinct "CWMS_20"."AV_CWMS_TS_ID2"."TS_CODE", "CWMS_20"."AV_CWMS_TS_ID2"."CWMS_TS_ID", "CWMS_20"."AV_CWMS_TS_ID2"."UNIT_ID"
from "CWMS_20"."AV_CWMS_TS_ID2"
where (
"CWMS_20"."AV_CWMS_TS_ID2"."CWMS_TS_ID" in ('HAMM.Stage.Inst.15Minutes.0.Decodes-Raw')
and "CWMS_20"."AV_CWMS_TS_ID2"."DB_OFFICE_ID" = 'SWT'
)
),
"tsv_limited" as (
select *
from "CWMS_20"."AT_TSV_2023"
where (
"AT_TSV_2023"."DATE_TIME" between date '2024-06-24' and date '2024-07-22'
and "AT_TSV_2023"."TS_CODE" in (
select "base_ids"."TS_CODE"
from "base_ids"
)
)
union all
select *
from "CWMS_20"."AT_TSV_2024"
where (
"AT_TSV_2024"."DATE_TIME" between date '2024-06-24' and date '2024-07-22'
and "AT_TSV_2024"."TS_CODE" in (
select "base_ids"."TS_CODE"
from "base_ids"
)
)
),
"max_values" as (
select
"base_ids"."CWMS_TS_ID",
"base_ids"."UNIT_ID",
"tsv_limited"."TS_CODE",
"tsv_limited"."DATE_TIME",
"tsv_limited"."VALUE",
"tsv_limited"."VERSION_DATE",
"tsv_limited"."DATA_ENTRY_DATE",
"tsv_limited"."QUALITY_CODE",
"CWMS_20"."AT_TS_EXTENTS"."EARLIEST_ENTRY_TIME" "START_DATE",
"CWMS_20"."AT_TS_EXTENTS"."LATEST_ENTRY_TIME" "END_DATE",
max("tsv_limited"."DATE_TIME") over (partition by "tsv_limited"."TS_CODE") "max_date_time"
from "tsv_limited"
join "base_ids"
on "base_ids"."TS_CODE" = "tsv_limited"."TS_CODE"
join "CWMS_20"."AT_TS_EXTENTS"
on (
"CWMS_20"."AT_TS_EXTENTS"."TS_CODE" = "tsv_limited"."TS_CODE"
and "CWMS_20"."AT_TS_EXTENTS"."VERSION_TIME" = "tsv_limited"."VERSION_DATE"
)
)
select
"max_values"."CWMS_TS_ID",
"max_values"."DATE_TIME",
"max_values"."VERSION_DATE",
"max_values"."DATA_ENTRY_DATE",
"max_values"."QUALITY_CODE",
"max_values"."START_DATE",
"max_values"."END_DATE",
"CWMS_20"."CWMS_UTIL"."GET_DEFAULT_UNITS"(
"CWMS_20"."CWMS_TS"."GET_BASE_PARAMETER_ID"("max_values"."TS_CODE"),
'EN'
) "def_units",
"max_values"."DATE_TIME" "max_date_time",
"CWMS_20"."CWMS_UTIL"."CONVERT_UNITS"(
"max_values"."VALUE",
"max_values"."UNIT_ID",
"CWMS_20"."CWMS_UTIL"."GET_DEFAULT_UNITS"(
"CWMS_20"."CWMS_TS"."GET_BASE_PARAMETER_ID"("max_values"."TS_CODE"),
'EN'
)
) "value_at_max_date"
from "max_values"
where "max_values"."DATE_TIME" = "max_values"."max_date_time" |
|
Excellent Set that test up with a reasonable time assert, I think there's an existing check int the assertion. If not, and maybe there isn't since I wrote this... copy this over: https://github.com/opendcs/opendcs/blob/main/integrationtesting/fixtures/src/main/java/org/opendcs/fixtures/assertions/Waiting.java You're local performance probably isn't the right target, but something like 5 seconds, just to make sure we aren't causing performance regressions later on. |
|
A few changes:
Note: These integration tests are only to show time improvement from the old query to the new query. These tests are using the jdbc export and are not intended to be pushed anywhere. I am considering adding the .time(lessthan(5000 ms)) to the assertions in the current integration tests (Although the current IT aren't made for using with the export, so they would still pass under the time constraint because of a lack of populated data). |
There was a problem hiding this comment.
This should probably use the constants you added.
There was a problem hiding this comment.
Fixed. Sorry, I thought I had done that originally, but maybe after I resolved the merge conflicts this morning I might've accidentally changed them back.






Fixes #1078
Proposed query update that changes a single Timeseries/Recent request from 30 seconds down to half a second on our SWT db export.