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

TiFlash accept lossless data type change for mydatetime (#7815) #7818

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #7815

What problem does this PR solve?

Issue Number: close #7809

Problem Summary:

CREATE TABLE `t` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `create_time` datetime(0) DEFAULT CURRENT_TIMESTAMP(0),
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
);
insert into t(id) values (10);
alter table t set tiflash replica 1;

set tidb_isolation_read_engines='tiflash';
select * from t;

alter table t modify column create_time datetime(3);
select * from t;
(1105, 'other error for mpp stream: From MPP<gather_id:<gather_id:1, query_ts:1689587648738941000, local_query_id:4, server_id:835035, start_ts:442915264584220674>,task_id:1>: Code: 48, e.displayText() = DB::Exception: Reading mismatch data type pack. Cast from Nullable(MyDateTime(0)) to Nullable(MyDateTime(3)) is NOT supported, column_id=2: (while reading from DTFile: /Users/jayson/.tiup/data/TkG8bcE/tiflash-0/data/data/t_96/stable/dmf_4), e.what() = DB::Exception,')

--- the error message for release-6.5/release-7.1
(1105, 'other error for mpp stream: From MPP<query:<query_ts:1689327674311914000, local_query_id:6, server_id:987888, start_ts:442847113852485633>,task_id:1>: Code: 49, e.displayText() = DB::Exception: Check schema[i].type->equals(*storage_schema[i].type) failed, schema[i].name = table_scan_1, schema[i].type->getName() = Nullable(MyDateTime(3)), storage_schema[i].name = create_time, storage_schema[i].type->getName() = Nullable(MyDateTime(0)), e.what() = DB::Exception,')

The root cause is that TiFlash does not detect the datatype change from mydatetime(0) to mydatetime(3) or timestamp(0) to timestamp(3) or time(0) to time(3).

bool typeDiffers(const TiDB::ColumnInfo & a, const TiDB::ColumnInfo & b)
{
if (a.tp != b.tp || a.hasNotNullFlag() != b.hasNotNullFlag() || a.hasUnsignedFlag() != b.hasUnsignedFlag())
return true;
if (a.tp == TypeEnum || a.tp == TypeSet)
{
if (a.elems.size() != b.elems.size())
return true;
for (size_t i = 0; i < a.elems.size(); i++)
{
if (a.elems[i].first != b.elems[i].first)
return true;
}
return false;
}
else if (a.tp == TypeNewDecimal)
{
return a.flen != b.flen || a.decimal != b.decimal;
}
return false;
}

Enlarging the fsp of mydatetime/timestamp/time is a lossless change, TiFlash should detect and change the data type in place. Narrowing down the fsp of mydatetime/timestamp/time is a lossy change, TiDB will add a temporary column and reorganize the column data as other lossy type change.

What is changed and how it works?

  • Detect and accept the fsp enlarging of DATETIME/TIMESTAMP/TIME column type
    • Narrowing down in-place is not supported
  • Cast the column type when reading the existing column data from disk to the new column type before returning to the compute layer

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix a bug that query fails after changing the `fsp` of `DATETIME`/`TIMESTAMP`/`TIME` column type

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jul 18, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign solotzg for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/cherry-pick-not-approved labels Jul 18, 2023
@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Jul 18, 2023
@JaySon-Huang
Copy link
Contributor

will be fixed in #7813

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants