Skip to content

fix: Skip explain plans which lookup individual records and return no rows #5203

Merged
rgeyer merged 2 commits intomainfrom
rgeyer/dbo11y/explain_zero_rows
Jan 8, 2026
Merged

fix: Skip explain plans which lookup individual records and return no rows #5203
rgeyer merged 2 commits intomainfrom
rgeyer/dbo11y/explain_zero_rows

Conversation

@rgeyer
Copy link
Contributor

@rgeyer rgeyer commented Jan 7, 2026

Brief description of Pull Request

In MySQL, the query we're executing for explain plans gets an updated concrete query in performance_schema periodically.

For queries which look up a single row, by a primary key id, for a record which does not exist, no explain plan is created.

This created situations where a customer would sometimes see an explain plan, and sometimes not for a given query.

This PR simply refrains from logging the empty explain plan, such that the dbo11y UI should only find explain plan records with content for a given query.

Issue(s) fixed by this Pull Request

Fixes #4987

Notes to the Reviewer

This just debug logs the fact that we're skipping, and does not communicate with the user or the dbo11y UI in any way.

In the future, I'd like to add some additional telemetry which a user can opt-in to with their alloy config to have more visibility to the frequency with which individual queries are dropped for the various reasons.

PR Checklist

  • Tests updated

BEGIN_COMMIT_OVERRIDE
fix(database_observability): Skip explain plans which lookup individual records and return no rows (#5203)
END_COMMIT_OVERRIDE

@rgeyer rgeyer requested a review from a team as a code owner January 7, 2026 23:10
Comment on lines +695 to +696
msgBlock, _, _, err := jsonparser.Get(redactedByteExplainPlanJSON, "query_block", "message")
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking: if err != nil are we happy not doing anything and moving on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think yes. The most likely scenario is that it did not find the requested json node.

That said, this is probably not the most deterministic way to handle it. I should check for error, and empty string separately.

@rgeyer rgeyer merged commit b7c7cbb into main Jan 8, 2026
48 of 49 checks passed
@rgeyer rgeyer deleted the rgeyer/dbo11y/explain_zero_rows branch January 8, 2026 18:41
@grafana-alloybot grafana-alloybot bot mentioned this pull request Jan 8, 2026
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gracefully handle queries which do not return any rows when running explain plan

2 participants