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

[release-18.0] Direct PR. Fix regression where reference tables with a different name on sharded keyspaces were not routed correctly. #15788

Merged

Conversation

rohit-nayak-ps
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps commented Apr 24, 2024

Description

If a reference table is named differently in the sharded keyspace, inserts and updates to that table behave differently than if they had the same name. Looks like there was a regression somewhere between v16 and v18.

The only code change is in the dml planning, where tables are rerouted. Additionally unit tests and an e2e test has been added to validate the rerouting and protect against regression.

Note: since there has been significant refactors in the vtgate planner between v18 and the current main, this is being implemented as a standalone PR instead of following the backport route. #15796 will fix the issue in v19 and v20.

Test cases have been added for dmls with reference tables have been added:

  • with the same name as the source
  • with a different name as the source
  • with the different name as the source, but with an alias

Related Issue(s)

#15770

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

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Copy link
Contributor

vitess-bot bot commented Apr 24, 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 Apr 24, 2024
@github-actions github-actions bot added this to the v18.0.5 milestone Apr 24, 2024
@harshit-gangal harshit-gangal added Component: Query Serving Type: Regression 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 Type: Bug labels Apr 24, 2024
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@rohit-nayak-ps rohit-nayak-ps 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 Backport to: release-18.0 Needs to be back ported to release-18.0 NeedsBackportReason If backport labels have been applied to a PR, a justification is required Backport to: release-19.0 Needs to be back ported to release-19.0 labels Apr 25, 2024
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@rohit-nayak-ps rohit-nayak-ps changed the title Reference table routing: e2e test to repro error with reference table routing [release-18.0] Direct PR. Fix regression where reference tabels with a different name on sharded keyspaces were not routed correctly. Apr 25, 2024
@rohit-nayak-ps rohit-nayak-ps changed the title [release-18.0] Direct PR. Fix regression where reference tabels with a different name on sharded keyspaces were not routed correctly. [release-18.0] Direct PR. Fix regression where reference tables with a different name on sharded keyspaces were not routed correctly. Apr 25, 2024
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Comment on lines 56 to 60
tableName.Qualifier = vschemaTable.GetTableName().Qualifier
tableName.Name = sqlparser.NewIdentifierCS(vschemaTable.Name.String())
newAliasTbl := sqlparser.NewAliasedTableExpr(tableName, "")
aliasTbl.Expr = newAliasTbl.Expr
aliasTbl.As = newAliasTbl.As
Copy link
Member

Choose a reason for hiding this comment

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

The alias should be either an existing one or the reference table name. Should not be source table name.

Copy link
Member

Choose a reason for hiding this comment

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

better to add some tests around it in dml_cases.json

Copy link
Member

Choose a reason for hiding this comment

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

I see you have created a new test file for it. So, those can be added there.
DML with alias.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the test cases into reference_cases.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alias should be either an existing one or the reference table name. Should not be source table name.

So I should only change the qualifier and retain the existing alias' 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.

@harshit-gangal, updated the code as we discussed and added more test cases for queries where aliases are specified.

…ove additional test

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@deepthi
Copy link
Member

deepthi commented Apr 26, 2024

@vitessio/query-serving does this need to be back ported to v17?

@systay systay mentioned this pull request Apr 29, 2024
24 tasks
…d test cases for aliases

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review May 2, 2024 15:02
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
@harshit-gangal
Copy link
Member

@vitessio/query-serving does this need to be back ported to v17?

According to me, this DML routing of the reference table was added in v17. I am not sure about the regression referred to here.

@@ -463,7 +463,6 @@ func validateDryRunResults(t *testing.T, output string, want []string) {
w = strings.TrimSpace(w[1:])
result := strings.HasPrefix(g, w)
match = result
//t.Logf("Partial match |%v|%v|%v\n", w, g, match)
Copy link
Member

Choose a reason for hiding this comment

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

nit: should be removed or uncommented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove in the next vrep. PR.

Comment on lines +52 to +55
if vindexTbl != nil {
// vindex cannot be present in a dml statement.
return false, vterrors.VT09014()
}
Copy link
Member

Choose a reason for hiding this comment

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

not sure if this will happen? do you have a test case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the nil vindexTbl check? The same check is made above in the same function. So I assumed it was required. I can remove it, but is there any problem adding the extra check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merging as is for now: assuming an additional check is safe. Can remove later on if required.

@rohit-nayak-ps rohit-nayak-ps merged commit 87f67cf into vitessio:release-18.0 May 7, 2024
103 checks passed
@rohit-nayak-ps rohit-nayak-ps deleted the rohit/reference-table-alias branch May 7, 2024 17:42
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.

5 participants