Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtexplain: Fix setting up the column information #15275

Merged
merged 3 commits into from Feb 19, 2024

Conversation

dbussink
Copy link
Contributor

@dbussink dbussink commented Feb 17, 2024

In #13312 we fixed how we encode names in information_schema queries. The problem there though is that the GetColumnNamesQuery string was also used inside vtexplain. Its usage there was not updated for the new escaping logic.

This in turn leads to broken queries during vtexplain which then leads to a lot of logs. The issue here is not that we log a lot, we log that we actually do have a problem here which is the case.

This fixes the underlying issue of not correctly generating the query as we should.

Related Issue(s)

Part of #15242

Marked for backporting all the way to v16, since that's where the original change in #13312 was also back ported to.

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

In vitessio#13312 we fixed how we encode
names in information_schema queries. The problem there though is that
the `GetColumnNamesQuery` string was also used inside `vtexplain`. It's
usage there was not updated for the new escaping logic.

This in turn leads to broken queries during `vtexplain` which then leads
to a lot of logs. The issue here is not that we log a lot, we log that
we actually do have a problem here which is the case.

This fixes the underlying issue of not correctly generating the query as
we should.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink added Backport to: release-16.0 Backport to: release-17.0 Needs to be back ported to release-17.0 Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 labels Feb 17, 2024
Copy link
Contributor

vitess-bot bot commented Feb 17, 2024

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.

@vitess-bot vitess-bot bot added 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 labels Feb 17, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Feb 17, 2024
@@ -618,7 +618,7 @@ func (t *explainTablet) handleSelect(query string) (*sqltypes.Result, error) {

// Gen4 supports more complex queries so we now need to
// handle multiple FROM clauses
tables := make([]*sqlparser.AliasedTableExpr, len(selStmt.From))
tables := make([]*sqlparser.AliasedTableExpr, 0, len(selStmt.From))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found this bug as well while debugging. We create it with the length, which means subsequent append below would always create an even longer slice, negating this optimization plus having a lot of nil entries in this slice.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's really a golang design flaw. I've fallen for this many times.

@dbussink dbussink added Type: Bug Component: vtexplain changes made to vtexplain code and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says 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 Feb 17, 2024
@@ -474,8 +474,8 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options, collatio
}
tEnv.addResult(query, tEnv.getResult(likeQuery))

likeQuery = fmt.Sprintf(mysqlctl.GetColumnNamesQuery, "database()", sanitizedLikeTable)
query = fmt.Sprintf(mysqlctl.GetColumnNamesQuery, "database()", sanitizedTable)
likeQuery = fmt.Sprintf(mysqlctl.GetColumnNamesQuery, "database()", mysqlctl.EncodeEntityName(sanitizedLikeTable))

Choose a reason for hiding this comment

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

Is it correct to apply the encoding onto the like expression? It's not a table name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this creates a correctly escaped string from the input which is what we want here explicitly.

Copy link

codecov bot commented Feb 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (54c6dfc) 67.44% compared to head (4f04f20) 67.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15275      +/-   ##
==========================================
- Coverage   67.44%   67.44%   -0.01%     
==========================================
  Files        1561     1561              
  Lines      193193   193189       -4     
==========================================
- Hits       130304   130296       -8     
- Misses      62889    62893       +4     

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

Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

LGTM. Can we add/update a test to catch things like this in the future?

@dbussink
Copy link
Contributor Author

LGTM. Can we add/update a test to catch things like this in the future?

I don't really have a good idea for how to add one. We only seem to log the errors, not fail on them. I wonder if we should fail on them instead but I don't really know enough about vtexplain if that's desirable here or not.

@vitessio/query-serving Does anyone of you have an idea how to test for this case here?

@dbussink dbussink force-pushed the fix-vtexplain-column-lookup-issue branch from 9c769db to 939de97 Compare February 18, 2024 14:17
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink
Copy link
Contributor Author

@mattlord Added a test in 241d5f5, but not really happy with it. Would not mind if others have a better idea 😄.

@@ -618,7 +618,7 @@ func (t *explainTablet) handleSelect(query string) (*sqltypes.Result, error) {

// Gen4 supports more complex queries so we now need to
// handle multiple FROM clauses
tables := make([]*sqlparser.AliasedTableExpr, len(selStmt.From))
tables := make([]*sqlparser.AliasedTableExpr, 0, len(selStmt.From))
Copy link
Contributor

Choose a reason for hiding this comment

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

It's really a golang design flaw. I've fallen for this many times.

There's already `sqltypes.EncodeStringSQL` which implements the exact
same thing.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
@dbussink dbussink merged commit 9a78e7d into vitessio:main Feb 19, 2024
102 checks passed
@dbussink dbussink deleted the fix-vtexplain-column-lookup-issue branch February 19, 2024 10:23
vitess-bot pushed a commit that referenced this pull request Feb 19, 2024
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
dbussink pushed a commit that referenced this pull request Feb 19, 2024
…) (#15282)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
dbussink pushed a commit that referenced this pull request Feb 19, 2024
…) (#15281)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
dbussink pushed a commit that referenced this pull request Feb 19, 2024
…) (#15280)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
hmaurer added a commit to github/vitess-gh that referenced this pull request Mar 21, 2024
hmaurer added a commit to github/vitess-gh that referenced this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport to: release-17.0 Needs to be back ported to release-17.0 Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 Component: vtexplain changes made to vtexplain code Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants