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

VReplication: send unique key name to rowstreamer, which can then use with FORCE INDEX #14916

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

shlomi-noach
Copy link
Contributor

Description

Fixes #14915

This PR adds:

  • force_unique_key field in filter/rule.
  • OnlineDDL populates this field with desired unique key name.
  • Field sent to rowstreamer as query hint.
  • If rowstreamer sees said query hint, then it adds FORCE INDEX (...) to the streaming query.

Note: still unsure what's the best way to add testing. The observable changes are that the rowstreamer query now includes a force index clause, e.g.:

476:I0109 16:37:05.522045 4149073 rowstreamer.go:332] Streaming query: select /*+ MAX_EXECUTION_TIME(3600000) */ id, col1, alternative_id from t force index (`alternative_id_idx`) order by alternative_id

vstreamer/engine populates the query hint like so:

460:I0109 16:36:20.914991 4149073 engine.go:280] Streaming rows for query select /*vt+ ukColumns="alternative_id" ukForce="alternative_id_idx" */ id, col1, alternative_id from t, lastpk: []

Related Issue(s)

#14915

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

Deployment Notes

…ique_key, rowstreamer reads it and uses the value as FORCE INDEX hint

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Copy link
Contributor

vitess-bot bot commented Jan 9, 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 Jan 9, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 9, 2024
@shlomi-noach
Copy link
Contributor Author

I'm suggesting this should be backported to supported versions. Opinions?

@shlomi-noach shlomi-noach 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 labels Jan 9, 2024
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@@ -619,6 +620,7 @@ func (v *VRepl) analyzeBinlogSource(ctx context.Context) {
SourceUniqueKeyColumns: encodeColumns(&v.chosenSourceUniqueKey.Columns),
TargetUniqueKeyColumns: encodeColumns(&v.chosenTargetUniqueKey.Columns),
SourceUniqueKeyTargetColumns: encodeColumns(v.chosenSourceUniqueKey.Columns.MappedNamesColumnList(v.sharedColumnsMap)),
ForceUniqueKey: url.QueryEscape(v.chosenSourceUniqueKey.Name),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why we're doing URL escaping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's for when the index name has spaces, or quotes, or other special characters. The query hints parser will otherwise be unable to parse it correctly. Consider select /*vt+ ukForce="an index with spaces" */ -- the parser will only parse "an".

Comment on lines 54 to 56
if directives == "" {
return fmt.Sprintf(queryTemplate, "")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These lines are unnecessary as the subsequent line would return the same thing when directives is an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed redundant code.

Comment on lines +61 to +64
{"", "force index (`PRIMARY`) order by id"},
{"/*vt+ ukColumns=\"uk1\" ukForce=\"uk2\" */", "force index (`uk2`) order by uk1"},
{"/*vt+ ukForce=\"uk2\" */", "force index (`uk2`) order by uk1"},
{"/*vt+ ukColumns=\"uk1\" */", "order by uk1"},
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we could probably use a few more test cases, but this might be enough.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@6a0cc44). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14916   +/-   ##
=======================================
  Coverage        ?   47.28%           
=======================================
  Files           ?     1136           
  Lines           ?   238493           
  Branches        ?        0           
=======================================
  Hits            ?   112761           
  Misses          ?   117121           
  Partials        ?     8611           

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

@shlomi-noach
Copy link
Contributor Author

IMO this should be backported to supported versions seeing that vstreamer could run into degraded/impossible performance situations. The fix itself is fairly safe.

@shlomi-noach shlomi-noach added Backport to: release-16.0 and removed NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 10, 2024
@shlomi-noach shlomi-noach merged commit 61b12e6 into vitessio:main Jan 10, 2024
106 of 107 checks passed
@shlomi-noach
Copy link
Contributor Author

All backports have conflicts, that is expected.

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

Successfully merging this pull request may close these issues.

Bug Report: MySQL can choose filesort plan for rowstreamer non-PK reads, leading to repeated stream timeouts
3 participants