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

partition: make ExchangePartition follow check constraints(part1) #46021

Merged
merged 9 commits into from
Sep 22, 2023

Conversation

jiyfhust
Copy link
Contributor

@jiyfhust jiyfhust commented Aug 12, 2023

What problem does this PR solve?

Issue Number: close #45922

Problem Summary:

What is changed and how it works?

Part1:
only verify records by check constraints.
prohibiting insert or update records which not satisfy check constraints is not included.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed labels Aug 12, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 12, 2023

Hi @jiyfhust. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Aug 12, 2023
@tiprow
Copy link

tiprow bot commented Aug 12, 2023

Hi @jiyfhust. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mjonss
Copy link
Contributor

mjonss commented Aug 16, 2023

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Aug 16, 2023
@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Merging #46021 (c57a3a2) into master (8b15111) will increase coverage by 0.3514%.
Report is 50 commits behind head on master.
The diff coverage is 85.5172%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46021        +/-   ##
================================================
+ Coverage   73.0847%   73.4362%   +0.3514%     
================================================
  Files          1335       1359        +24     
  Lines        397994     412370     +14376     
================================================
+ Hits         290873     302829     +11956     
- Misses        88382      90995      +2613     
+ Partials      18739      18546       -193     
Flag Coverage Δ
integration 32.4563% <7.5862%> (?)
unit 73.7961% <85.5172%> (+0.7113%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser 85.3266% <ø> (+0.3394%) ⬆️
br 49.4444% <ø> (-3.4981%) ⬇️

@jiyfhust
Copy link
Contributor Author

/test check-dev

@tiprow
Copy link

tiprow bot commented Aug 17, 2023

@jiyfhust: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test check-dev

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jiyfhust
Copy link
Contributor Author

It is ready for review now. @mjonss

ddl/partition.go Outdated Show resolved Hide resolved
ddl/partition.go Outdated
pCons := getWriteableConstraintExpr(pt.Constraints)
nCons := getWriteableConstraintExpr(nt.Constraints)
if len(pCons) > 0 {
if err := verifyFunc(nschemaName, nt.Name.L, "", pCons); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to combine this with the verification in checkExchangePartitionRecordValidation so we can do a single scan of the non-partitioned table, and fail at the first row that neither match the partition or the partitioned tables condition?

ddl/tests/partition/db_partition_test.go Outdated Show resolved Hide resolved
ddl/partition.go Outdated Show resolved Hide resolved
ddl/partition.go Outdated Show resolved Hide resolved
@jiyfhust jiyfhust requested a review from mjonss August 31, 2023 11:02
@jiyfhust
Copy link
Contributor Author

jiyfhust commented Sep 5, 2023

PTAL @mjonss

ddl/partition.go Outdated
@@ -2446,6 +2453,21 @@ func (w *worker) onExchangeTablePartition(d *ddlCtx, t *meta.Meta, job *model.Jo
job.State = model.JobStateRollingback
return ver, errors.Trace(err)
}
if variable.EnableCheckConstraint.Load() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer if the check is combined with the checkExchangePartitionRecordValidation above, to only do a single scan of the non-partitioned table.

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 16, 2023
@jiyfhust
Copy link
Contributor Author

/retest

1 similar comment
@jiyfhust
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 19, 2023
Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

Please create a followup issue, to test null handling in validation, since I assume there may be hidded issues in non-list cases?

Comment on lines +3446 to +3448
buf.WriteString("mod(")
buf.WriteString(pi.Expr)
buf.WriteString(", %?) != %?")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any tests that validates NULLs for Hash partitions? (not blocking this PR, just curious)

Comment on lines +3504 to +3519
if variable.EnableCheckConstraint.Load() {
ncc, ok := ntbl.(CheckConstraintTable)
if !ok {
return errors.Errorf("exchange partition process assert table partition failed")
}
nCons := ncc.WritableConstraint()
if len(nCons) > 0 {
buf.Reset()
buf.WriteString("select 1 from %n.%n partition(%n) where ")
buf.WriteString(genConstraintCondition(nCons))
buf.WriteString(" limit 1")
err = verifyFunc(buf.String(), pschemaName, pt.Name.L, partitionName)
if err != nil {
return errors.Trace(err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

More of a note, a future improvement may be to run the validations in parallel.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjonss, tiancaiamao

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 21, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 21, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-19 17:07:33.913456549 +0000 UTC m=+623619.881044600: ☑️ agreed by tiancaiamao.
  • 2023-09-21 06:58:21.491198577 +0000 UTC m=+759867.458786626: ☑️ agreed by mjonss.

@jiyfhust
Copy link
Contributor Author

Please create a followup issue, to test null handling in validation, since I assume there may be hidded issues in non-list cases?

Issue created #47167.

@jiyfhust
Copy link
Contributor Author

/retest

2 similar comments
@jiyfhust
Copy link
Contributor Author

/retest

@wuhuizuo
Copy link
Contributor

/retest

@ti-chi-bot ti-chi-bot bot merged commit cfa9ffd into pingcap:master Sep 22, 2023
@jiyfhust jiyfhust deleted the exchangepartition_check_part1 branch September 22, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EXCHANGE PARTITION does not follow CHECK Constraints
4 participants