Skip to content

vtgate: ignore MySQL client probe query select $$ in querylog#20073

Closed
ChaitanyaD48 wants to merge 2 commits into
vitessio:mainfrom
ChaitanyaD48:fix/vtgate-ignore-mysql-probe-query
Closed

vtgate: ignore MySQL client probe query select $$ in querylog#20073
ChaitanyaD48 wants to merge 2 commits into
vitessio:mainfrom
ChaitanyaD48:fix/vtgate-ignore-mysql-probe-query

Conversation

@ChaitanyaD48
Copy link
Copy Markdown
Contributor

Description

MySQL 8.4+ clients (mysql CLI, Percona fork) unconditionally send select $$ immediately after the handshake to probe whether the server supports $$ as a quoting style. This is hardcoded in the client ([upstream commit (https://github.com/mysql/mysql-server/commit/9c7bc2973110861b731311f8b42af152f62d65af)) and cannot be disabled or suppressed by the user.

Vitess's SQL parser does not recognize $$ as valid syntax, so every new connection from a MySQL 8.4+ client produces a parse-error entry in vtgate's query log.

Before

image

After

image

Related Issue(s)

Fixes #19610

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

…elect 31239

Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
…eamlog

Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
Copilot AI review requested due to automatic review settings May 9, 2026 11:27
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels May 9, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone May 9, 2026
@vitess-bot
Copy link
Copy Markdown
Contributor

vitess-bot Bot commented May 9, 2026

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Filters out the MySQL 8.4+ client “probe” query (select $$) from Vitess query logging to avoid unavoidable parse-error noise on new client connections.

Changes:

  • Suppress query-log emission when the SQL is exactly select $$ (case-insensitive, surrounding whitespace ignored).
  • Add unit tests covering the suppression behavior and ensuring similar queries still log normally.
  • Minor formatting-only adjustments in streamlog counter declarations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
go/streamlog/streamlog.go Add early suppression in QueryLogConfig.ShouldEmitLog for the select $$ probe query.
go/streamlog/streamlog_test.go Add test cases verifying select $$ is filtered while non-probe variants still emit.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.96%. Comparing base (70c7a72) to head (1f4d8d4).
⚠️ Report is 241 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #20073       +/-   ##
===========================================
+ Coverage   69.67%   83.96%   +14.29%     
===========================================
  Files        1614        2     -1612     
  Lines      216793      131   -216662     
===========================================
- Hits       151044      110   -150934     
+ Misses      65749       21    -65728     
Flag Coverage Δ
partial 83.96% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread go/streamlog/streamlog.go
Comment on lines +295 to +300
// MySQL 8.4+ clients send "select $$" at connection time to probe dollar-quote
// syntax support. This is hardcoded client behavior that cannot be disabled;
// suppress it to avoid log noise.
if strings.EqualFold(strings.TrimSpace(sql), "select $$") {
return false, ""
}
Copy link
Copy Markdown
Member

@mattlord mattlord May 9, 2026

Choose a reason for hiding this comment

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

IMO... clients can send whatever queries they want. It's not up to the Vitess developers to decide what should and should not be logged. It's a log of queries coming from clients.

And IMO every Vitess user should not pay the cost of an EqualFold on every query just to elide it. The use case in the issue was:

For integration load testing I have scripts that spin up a lot of parallel connections to the database, and every time a mysql client initiates a new connection to the server I get a log message in the vtgate log about the invalid query. As it's a hard-coded query that is meaningless (as far as I can tell) and completely out of my control, that is just unnecessary noise in the query log.

IMO we should not modify how Vitess behaves for all users simply so that it fits better into that very narrow use case / scenario, especially when there seems to be a pretty clear performance cost.

Am I missing or misunderstanding something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What might make sense though... is providing a Viper config option that allowed users to specify a set of SQL query shapes to ignore in the logs. What do you think about that? Then a user could specify this specific query and any others coming from their clients that they want to elide from the vtgate logs.

Copy link
Copy Markdown
Contributor Author

@ChaitanyaD48 ChaitanyaD48 May 16, 2026

Choose a reason for hiding this comment

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

@mattlord Thanks for the review! Its a Good Idea to have a user configurable viper config option to ignore a set of SQL Query shapes in Logs.

I have some questions around this -

Question 1: How should we "match" a query?

Should we match by normalized shape or exact string? In case of Reading "query shape" as the output of sqlparser.RedactSQLQuery, select 31239 and select 99999 would both collapse to a single entry like select :vtg1 but, select $$ itself doesn't parse, so RedactSQLQuery fails on it. We'd need a fallback for the un-parseable cases. The options I see:

  1. Shape-match when parseable, raw-string fallback otherwise.
  2. Just raw-string match (case/whitespace-insensitive), skipping normalization entirely.

Which approach do you think makes more sense?


And Addressing your performance Concern. I feel this new user-configurable viper config option must sit at the executor level in vtgate, not inside streamlog's ShouldEmitLog. Planning to go with a len() == 0 fast path something like -

func shouldIgnoreInQueryLog(sql string) bool {
    if len(ignoredQueries) == 0 {
        return false   // ← fast path: users who don't opt-in land here
    }
    // expensive part: match sql string,  do map lookup, etc.
    normalized := strings.ToLower(strings.TrimSpace(sql))
    _, found := ignoredQueriesMap[normalized]
    return found
}

for users who don't opt in pay essentially nothing (one int compare), and users who do pay a single map lookup per query. That should keep the cost off everyone except the operators who actually asked for it.

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should do it by shape or the normalized form where the variable parts are replaced by a placeholder.

For the performance part, that sounds good. Thanks! ❤️

Copy link
Copy Markdown
Contributor Author

@ChaitanyaD48 ChaitanyaD48 May 23, 2026

Choose a reason for hiding this comment

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

Got it, thanks @mattlord!
I've created a new issue (#20173) and opened a PR (#20174) for the proposed change.

Closing this PR.

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

Labels

NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore 'select $$' in query log

3 participants