Skip to content

Add a RFC to optimize common trace DB queries#24

Open
mprahl wants to merge 3 commits into
mlflow:mainfrom
mprahl:postgres-optimization2
Open

Add a RFC to optimize common trace DB queries#24
mprahl wants to merge 3 commits into
mlflow:mainfrom
mprahl:postgres-optimization2

Conversation

@mprahl

@mprahl mprahl commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Supersedes #23

This was coauthored by @aws-khatria.

Co-authored-by: Ayush Khatri <khatria@amazon.com>
Signed-off-by: mprahl <mprahl@users.noreply.github.com>
ON assessments (experiment_id, trace_timestamp_ms);

CREATE INDEX idx_assessments_exp_trace_ts_name
ON assessments (experiment_id, trace_timestamp_ms, name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't the two indexes above redundant? I believe in postgres and SQLite, the second index can be used for any query the first would.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it can be reused but it's not as efficient. I added a comment explaining it.


These numbers are benchmark-based targets, not guarantees. Exact percentile queries may still
retain significant sort cost even after the denormalization work, and are expected to remain the
main residual cost on the slowest paths.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to also benchmark writes

@etirelli etirelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of minor comments.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
@mprahl mprahl requested a review from etirelli July 9, 2026 21:49
@mprahl

mprahl commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

@etirelli could you please take another look? I added a commit with a proposal for rollup tables.

- adding targeted indexes for assessment and span-cost workloads
- cleaning up duplicated EAV rows once the denormalized columns become authoritative

On a load test with 10M traces, 30M spans, and 30M assessments in one experiment, the current Usage

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, is this load generator available somewhere?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some load generators available in the MLflow repo:

  • .github/workflows/tracing-benchmark.yml
  • dev/benchmarks/tracing/README.md
  • dev/benchmarks/tracing/test_trace_perf.py
  • dev/benchmarks/tracing/_data.py

That said, the exact 10M-trace Postgres UI replay harness used for these RFC numbers was a local/ad hoc load harness derived from the tracing benchmark utilities to speed up trace ingestion.

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
similar non-analytic annotations can remain mutable. Adding assessments to older traces should also
remain allowed, since human review and evaluator backfills often happen after the trace is closed.

Assessment writes or trace deletes against already-rolled-up traces should delete stale rollup rows

@etirelli etirelli Jul 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mark the row as stale instead of deleting? considering queries to the metrics issued after an update to a non-fresh trace, if the row was deleted, the data point for that day would be missing completely, while if we simply mark it as stale, the previous result would be returned/computed (eventual consistency).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etirelli I'm torn about this. I think I lean towards the eventual consistency you suggest but it does mean the metrics would be inaccurate. Perhaps a compromise is to show a warning in the UI that the metrics are out of date and being refreshed?

What do you think @B-Step62?

rollup-supported shape, especially arbitrary filtered requests and non-daily exact percentile
queries, still fall back to the raw path and remain the main residual cost.

## Drawbacks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: "trade-offs" instead of "drawbacks"? :)

@etirelli

Copy link
Copy Markdown
Contributor

@mprahl LGTM

The query numbers look great!

Did you benchmark writing impact on a loaded DB (i.e., writing performance after pre-loading the DB with the test data)? I don't believe the impact would be significant, but still a good datapoint to have.

@mprahl

mprahl commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

@mprahl LGTM

The query numbers look great!

Did you benchmark writing impact on a loaded DB (i.e., writing performance after pre-loading the DB with the test data)? I don't believe the impact would be significant, but still a good datapoint to have.

Thanks for the review! I haven't tested it but I'll try to give that a shot today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants