Skip to content

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Jun 27, 2025

What this PR does

This PR makes two changes to common subexpression elimination:

  • Tests: I was worried we weren't handling the case where a expression has multiple children correctly, so added some tests to check. Turns out this case is OK, but I think it'd be valuable to retain so it's not broken in the future.
  • Metric: the existing cortex_mimir_query_engine_common_subexpression_elimination_duplication_nodes_introduced metric is useful for gauging the impact of CSE, but doesn't tell us how much load on ingesters and store-gateways we've avoided. The new metric tells us the number of selectors eliminated and therefore gives us a better idea of the number of avoided ingester and store-gateway requests.

Which issue(s) this PR fixes or relates to

#11189

Checklist

  • Tests updated.
  • [n/a] Documentation added.
  • [covered by Mimir Query Engine #10067] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]. If changelog entry is not needed, please add the changelog-not-needed label to the PR.
  • [n/a] about-versioning.md updated with experimental features.

@charleskorn charleskorn added the changelog-not-needed PRs that don't need a CHANGELOG.md entry label Jun 27, 2025
@charleskorn charleskorn marked this pull request as ready for review June 27, 2025 04:31
@charleskorn charleskorn requested a review from a team as a code owner June 27, 2025 04:31
@charleskorn charleskorn changed the title MQE: add tests for common subexpression elimination for expressions with multiple children MQE: add tests for common subexpression elimination for expressions with multiple children, and add metric on number of selectors eliminated Jun 27, 2025
Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -50,7 +55,7 @@ func (e *OptimizationPass) Apply(_ context.Context, plan *planning.QueryPlan) (*
paths := e.accumulatePaths(plan)

// For each path: find all the other paths that terminate in the same selector, then inject a duplication node
err := e.groupAndApplyDeduplication(paths, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Stylistic choice but: If the groupAndApplyDeduplication() method was changed to return a count of the number of selectors eliminated, we could remove the "have eliminated" boolean and increment the metric here single time. I don't feel strongly either way.

Copy link
Contributor Author

@charleskorn charleskorn Jun 30, 2025

Choose a reason for hiding this comment

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

Good idea. How's #11900?

@charleskorn
Copy link
Contributor Author

charleskorn commented Jun 29, 2025

Given the approval, I'm going to merge this as-is so it's part of this week's release while we discuss #11879 (comment)

@charleskorn charleskorn merged commit 3f8bde8 into main Jun 29, 2025
31 checks passed
@charleskorn charleskorn deleted the charleskorn/cse-test-case branch June 29, 2025 23:24
charleskorn added a commit that referenced this pull request Jun 30, 2025
… "selectors inspected" metric (#11900)

#### What this PR does

This PR builds on #11879,
addressing
#11879 (comment) and
adding an additional "selectors inspected" metric.

#### Which issue(s) this PR fixes or relates to

#11879

#### Checklist

- [x] Tests updated.
- [n/a] Documentation added.
- [covered by #10067] `CHANGELOG.md` updated - the order of entries
should be `[CHANGE]`, `[FEATURE]`, `[ENHANCEMENT]`, `[BUGFIX]`. If
changelog entry is not needed, please add the `changelog-not-needed`
label to the PR.
- [n/a]
[`about-versioning.md`](https://github.com/grafana/mimir/blob/main/docs/sources/mimir/configure/about-versioning.md)
updated with experimental features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-not-needed PRs that don't need a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants