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

ddl: fill in original default for extra writable columns in batch insert (#40198) #53053

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #40198

Signed-off-by: YangKeao yangkeao@chunibyo.icu

What problem does this PR solve?

Issue Number: close #40192, close #50993

Problem Summary:

When a column is in write-only state, the INSERT ignore statement without specifying columns doesn't fill in the origin default value. INSERT actually works, because it appends, see

tidb/table/tables/tables.go

Lines 798 to 813 in 95f0dc5

if col.State != model.StatePublic &&
// Update call `AddRecord` will already handle the write only column default value.
// Only insert should add default value for write only column.
!opt.IsUpdate {
// If col is in write only or write reorganization state, we must add it with its default value.
value, err = table.GetColOriginDefaultValue(sctx, col.ToInfo())
if err != nil {
return nil, err
}
// add value to `r` for dirty db in transaction.
// Otherwise when update will panic cause by get value of column in write only state from dirty db.
if col.Offset < len(r) {
r[col.Offset] = value
} else {
r = append(r, value)
}

This case can also work well with unique index (if the origin default value is NULL) and NOT NULL.

It also avoids inserting more than 1 rows if the columns is NOT NULL and write-only (as the user cannot set a value for it). I doubt whether it is expected. (However, many other places depend on this behavior, and as I've tried, modifying this behavior is really scarying... I didn't touch it in this PR).

What is changed and how it works?

Append the origin default value if there are extra write-only column.

Check List

Tests

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

Release note

Fix the issue that batch inserting data while dropping column could cause panic.

@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.5-20230625-v6.5.3 labels May 7, 2024
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
@ti-chi-bot ti-chi-bot force-pushed the cherry-pick-40198-to-release-6.5-20230625-v6.5.3 branch from e1ff702 to cfbc908 Compare May 7, 2024 05:38
Defined2014
Defined2014 previously approved these changes May 7, 2024
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels May 7, 2024
hawkingrei
hawkingrei previously approved these changes May 7, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 7, 2024
Copy link

ti-chi-bot bot commented May 7, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-07 05:57:00.563269505 +0000 UTC m=+941574.320405073: ☑️ agreed by Defined2014.
  • 2024-05-07 05:58:11.181668099 +0000 UTC m=+941644.938803672: ☑️ agreed by hawkingrei.

@xhebox
Copy link
Contributor

xhebox commented May 7, 2024

/test build

Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox dismissed stale reviews from hawkingrei and Defined2014 via d7c916e May 7, 2024 06:05
@ti-chi-bot ti-chi-bot bot removed the approved label May 7, 2024
Signed-off-by: xhe <xw897002528@gmail.com>
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 7, 2024
Defined2014
Defined2014 previously approved these changes May 7, 2024
@ti-chi-bot ti-chi-bot bot added the approved label May 7, 2024
Signed-off-by: xhe <xw897002528@gmail.com>
Copy link

ti-chi-bot bot commented May 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014

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

The pull request process is described 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 the approved label May 7, 2024
Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 6 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (release-6.5-20230625-v6.5.3@ecc2f3e). Click here to learn what that means.

Additional details and impacted files
@@                       Coverage Diff                        @@
##             release-6.5-20230625-v6.5.3     #53053   +/-   ##
================================================================
  Coverage                               ?   73.4130%           
================================================================
  Files                                  ?       1080           
  Lines                                  ?     346459           
  Branches                               ?          0           
================================================================
  Hits                                   ?     254346           
  Misses                                 ?      75690           
  Partials                               ?      16423           

@ti-chi-bot ti-chi-bot bot merged commit 5e74466 into pingcap:release-6.5-20230625-v6.5.3 May 7, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm 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-20230625-v6.5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants