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

table: support check constraint in insert and update #11

Merged
merged 2 commits into from
Jun 10, 2020

Conversation

imtbkcat
Copy link
Collaborator

@imtbkcat imtbkcat commented Jun 8, 2020

What problem does this PR solve?

close pingcap#17425

What is changed and how it works?

  • Add Constraint class
  • Build constraint object while initilize table object
  • Eval and check constraint expression in UpdateRecord and AddRecord

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression

Related changes

  • None

Release note

  • Write release note for bug-fix or new feature.

Copy link

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

Rest LGTM

t.tableID = tblInfo.ID
t.physicalTableID = physicalTableID
t.allocs = allocs
t.meta = tblInfo
t.Columns = cols
t.PublicConstraints = constraints
Copy link

@AilinKid AilinKid Jun 9, 2020

Choose a reason for hiding this comment

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

how about rename t.PublicConstraints to t.Constraints , which means the constraints in all state?

}
writeableConstraint := make([]*table.Constraint, 0, len(t.PublicConstraints))
for _, con := range t.PublicConstraints {
if con.State == model.StateDeleteOnly || con.State == model.StateDeleteReorganization {
Copy link

Choose a reason for hiding this comment

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

constraint only has 3 state: None -> WriteOnly -> Public, but the code correctness here is ok.

if shouldWriteBinlog(ctx) && !t.canSkipUpdateBinlog(col, value) {
binlogColIDs = append(binlogColIDs, col.ID)
binlogOldRow = append(binlogOldRow, oldData[col.Offset])
binlogNewRow = append(binlogNewRow, value)
}
}

if len(t.WritableConstraint()) != 0 {
for _, constraint := range t.WritableConstraint() {
ok, isNull, err := constraint.ConstraintExpr.EvalInt(ctx, chunk.MutRowFromDatums(rowToCheck).ToRow())
Copy link

Choose a reason for hiding this comment

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

should it be EvalBool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EvalBool has some problem, which sometimes can not return correct isNull

Copy link

Choose a reason for hiding this comment

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

ok

Copy link

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Owner

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133 bb7133 merged commit bfb74ae into bb7133:4.0-itai Jun 10, 2020
bb7133 pushed a commit that referenced this pull request Oct 11, 2021
* mysql: Add NO_AUTO_CREATE_USER detection
* mysql: Update Default SQL Mode
* Include No_auto_create_user and only_full_group_by
CbcWestwolf added a commit to CbcWestwolf/tidb that referenced this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants