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

schemadiff: fix diffing of textual columns with implicit charsets #14930

Merged

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Jan 10, 2024

Description

See story in #14929. Also, see test cases added in diff_test.go to understand the nuances of TableCharsetCollateStrategy.

In this PR:

  • Main change is in column.go, ColumnDefinitionEntity.ColumnDiff() investigates not only the from/to columns, but also the from/to tables' charset/collation, and temporarily populates column with any missing data so as to have a true comparison.
  • To that effect, a new helper charsetCollate struct was introduced, and used throughout table.go as the diff result of two tables' charset/collations.

Update: merged another PR

In a game of pass-the-ball, this PR now includes #14934 (which originally started off this PR). Please see description on #14934

Related Issue(s)

Fixes #14929

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: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…eIgnoreAlways behavior

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

vitess-bot bot commented Jan 10, 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 10, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 10, 2024
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 55 lines in your changes are missing coverage. Please review.

Comparison is base (9df71e0) 47.26% compared to head (26acffc) 47.31%.
Report is 4 commits behind head on main.

Files Patch % Lines
go/vt/schemadiff/column.go 59.64% 20 Missing and 3 partials ⚠️
go/vt/sidecardb/sidecardb.go 64.28% 8 Missing and 2 partials ⚠️
go/vt/schemadiff/table.go 88.63% 4 Missing and 1 partial ⚠️
go/vt/schemadiff/diff.go 87.50% 3 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 40.00% 3 Missing ⚠️
go/vt/vttablet/onlineddl/executor.go 0.00% 3 Missing ⚠️
go/vt/vtctl/workflow/materializer.go 0.00% 2 Missing ⚠️
go/vt/wrangler/materializer.go 33.33% 2 Missing ⚠️
go/vt/vttablet/onlineddl/vrepl.go 0.00% 1 Missing ⚠️
go/vt/vttablet/tabletserver/schema/engine.go 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14930      +/-   ##
==========================================
+ Coverage   47.26%   47.31%   +0.04%     
==========================================
  Files        1136     1137       +1     
  Lines      238484   238684     +200     
==========================================
+ Hits       112721   112923     +202     
+ Misses     117158   117152       -6     
- Partials     8605     8609       +4     

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

@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 NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 10, 2024
if c.IsTextual() || other.IsTextual() {
switch hints.TableCharsetCollateStrategy {
case TableCharsetCollateStrict:
// No need to do anything
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is correct. Also in this case we can get an empty / column charset due to normalization if you change the table level charset and we shouldn't then generate a diff.

This is actually visible in a broken test that was added.

from: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin) default charset=latin1",
to: "create table t (a varchar(64) CHARACTER SET latin1 COLLATE latin1_bin)",
diff: "alter table t modify column a varchar(64) character set latin1 collate latin1_bin, charset utf8mb4, algorithm = COPY",
cdiff: "ALTER TABLE `t` MODIFY COLUMN `a` varchar(64) CHARACTER SET latin1 COLLATE latin1_bin, CHARSET utf8mb4, ALGORITHM = COPY",
Copy link
Contributor

Choose a reason for hiding this comment

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

This test expectation is wrong. In this case there should not be a MODIFY COLUMN, since the charset / collation of the column doesn't actually change. This should only be alter table t charset utf8mb4 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Looking into it.

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've fixed the expected output, so that now the PR should be failing until the logic is adapted.

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

@dbussink please review the new and improved tests in:

The tests now all pass. If you agree that the tests are correct, then we're good.

@shlomi-noach shlomi-noach changed the title scheadiff: handle TableCharsetCollateIgnoreAlways and TableCharsetCollateIgnoreEmpty correctly scheadiff: fix diffing of textual columns with implicit charsets Jan 10, 2024
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
We already had the parser that needed to be injected, but in order to
properly handle MySQL 5.7 we also need to inject collations
configuration. Instead of adding more arguments, we introduce the
schemadiff environment struct and use that to inject the things like the
current parser and current collation environment and default collation.

Also need to refactor the rest that ends up using schemadiff to inject
it similarly.

The core goal here is that the sidecar can properly inject the right
collation as well so we can unblock fixing the case sensitivity there.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
…hout a charset, we use Envronment to autopopulate the charset, or return an error what that is not possible

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…hout a charset, we use Envronment to autopopulate the charset, or return an error what that is not possible

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

Update: merged another PR

In a game of pass-the-ball, this PR now includes #14934 (which originally started off this PR). Please see description on #14934

@dbussink dbussink changed the title scheadiff: fix diffing of textual columns with implicit charsets schemadiff: fix diffing of textual columns with implicit charsets Jan 11, 2024
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

LGTM! Thankyou for fixing this!

@GuptaManan100 GuptaManan100 merged commit eddb39e into vitessio:main Jan 12, 2024
102 checks passed
@GuptaManan100 GuptaManan100 deleted the schemadiff-charset-columns-table branch January 12, 2024 06:18
shlomi-noach added a commit to planetscale/vitess that referenced this pull request May 8, 2024
…olumns with implicit charsets

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants