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) #51145

Merged

Conversation

ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Feb 19, 2024

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.

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
@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 This PR is cherry-picked to release-6.5 from a source PR. labels Feb 19, 2024
Copy link
Collaborator

@Benjamin2037 Benjamin2037 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 19, 2024
@ti-chi-bot ti-chi-bot bot added the lgtm label Feb 19, 2024
Copy link

ti-chi-bot bot commented Feb 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Benjamin2037, tangenta

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 approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 19, 2024
Copy link

ti-chi-bot bot commented Feb 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-02-19 08:23:14.593631388 +0000 UTC m=+259083.341254500: ☑️ agreed by Benjamin2037.
  • 2024-02-19 08:29:23.19662444 +0000 UTC m=+259451.944247552: ☑️ agreed by tangenta.

@tangenta
Copy link
Contributor

/retest

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

❗ No coverage uploaded for pull request base (release-6.5@f4dabb9). Click here to learn what that means.
The diff coverage is 71.4285%.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-6.5     #51145   +/-   ##
================================================
  Coverage               ?   73.6206%           
================================================
  Files                  ?       1094           
  Lines                  ?     350623           
  Branches               ?          0           
================================================
  Hits                   ?     258131           
  Misses                 ?      75910           
  Partials               ?      16582           

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Feb 20, 2024
@ti-chi-bot ti-chi-bot bot merged commit a63aa6e into pingcap:release-6.5 Feb 20, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm 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 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.

4 participants