-
[OPIK-6550] [BE] perf: skip row-numbering CTE in version-id lookups (#6727)
发布于
2026-05-15 10:39:54 +00:00 - [OPIK-6550] [BE] perf: skip row-numbering CTE in version-id lookups
POST /v1/private/datasets/items/stream and resolveVersionId only need a
UUID, but DatasetVersionDAO.findByTag and findByHash compute a per-version
ROW_NUMBER() over every version of the dataset to assemble a display name
that is then discarded. As dataset version counts grow, this scan
saturates the MySQL reader (~830 stream calls/hour against ~37k versions
was enough to push CPU to 80-99%).Add findVersionIdByTag (PK lookup on dataset_version_tags) and
findVersionIdByHash (unique-key lookup on dataset_versions), expose
getLatestVersionId on DatasetVersionService, refactor resolveVersionId
to use both lightweight lookups, and swap the streaming-latest call site
in DatasetItemService. The existing findByTag/findByHash and
getLatestVersion remain unchanged so paths that need the display name
are unaffected.- test(opik-backend): use READ_ONLY for lightweight version-id lookup helpers
Address review feedback: the helpers only call @SqlQuery reads, so they
should follow the READ_ONLY pattern from .agents/skills/opik-backend/mysql.md
rather than WRITE.下载附件