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

txn: support multi-table join in nt-dml #39139

Merged
merged 8 commits into from
Nov 24, 2022
Merged

Conversation

ekexium
Copy link
Contributor

@ekexium ekexium commented Nov 14, 2022

Signed-off-by: ekexium eke@fastmail.com

What problem does this PR solve?

Issue Number: ref #33485

Problem Summary:

This PR adds support for multi-join in nontransactional DML.

The remaining problems

  • Updating the shard column should not be allowed
  • Using the shard column as join key should not be allowed

What is changed and how it works?

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
Copy link
Member

ti-chi-bot commented Nov 14, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • sticnarf
  • you06

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 14, 2022
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 14, 2022
@ti-chi-bot ti-chi-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 Nov 16, 2022
Signed-off-by: ekexium <eke@fastmail.com>
@ekexium ekexium marked this pull request as ready for review November 16, 2022 07:08
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 16, 2022
@ekexium ekexium requested a review from you06 November 16, 2022 07:39
@@ -197,11 +205,11 @@ func checkConstraint(stmt *ast.NonTransactionalDMLStmt, se Session) error {
return nil
}

func checkTableRef(t *ast.TableRefsClause) error {
func checkTableRef(t *ast.TableRefsClause, allowMultipleTables bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see allowMultipleTables is always true now, is this check need to fail with multi tables in some future conditions?

Copy link
Contributor Author

@ekexium ekexium Nov 21, 2022

Choose a reason for hiding this comment

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

Maybe. I'm not sure about Updates and Deletes. If we find them error-prone in tests we could disable multiple table joins for them.

parser/ast/dml.go Outdated Show resolved Hide resolved
session/nontransactional.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 17, 2022
@ekexium
Copy link
Contributor Author

ekexium commented Nov 21, 2022

The remaining problems

Updating the shard column should not be allowed
Using the shard column as join key should not be allowed

Checking these constraints is kinda complex. I'll leave them to a following PR.

Copy link
Contributor

@sticnarf sticnarf left a comment

Choose a reason for hiding this comment

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

Is there any test for selecting sharding key automatically with clustered index?

Comment on lines +721 to +722
// if the clustered index contains multiple columns, we cannot automatically choose a column as the shard column
return false, nil, errors.New("Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a TODO? Multi-column clustered index seems doable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean by selecting the first column? That column might be highly skewed. So I'd rather let user manually specify it.

Is there any test for selecting sharding key automatically with clustered index?

It's in TestNonTransactionalWithAutoDetectShardColumn

Copy link
Contributor

Choose a reason for hiding this comment

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

Single column can be highly skewed too. I don't get why multi-column is special.

I thought you didn't do it just because of implementation...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, actually I don't mean using first column only. To support multiple columns, we need to scan batches of keys containing all columns in the clustered index.

@ekexium
Copy link
Contributor Author

ekexium commented Nov 21, 2022

/run-all-tests

Copy link
Contributor

@sticnarf sticnarf 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 removed the status/LGT1 Indicates that a PR has LGTM 1. label Nov 21, 2022
@ti-chi-bot ti-chi-bot added the status/LGT2 Indicates that a PR has LGTM 2. label Nov 21, 2022
Signed-off-by: ekexium <eke@fastmail.com>
Signed-off-by: ekexium <eke@fastmail.com>
@ekexium
Copy link
Contributor Author

ekexium commented Nov 24, 2022

@sticnarf Could you help merge it?

@sticnarf
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 8340eb0

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 24, 2022
@ti-chi-bot ti-chi-bot merged commit 84fa999 into pingcap:master Nov 24, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Nov 24, 2022

TiDB MergeCI notify

🔴 Bad News! [4] CI still failing after this pr merged.
These failed integration tests don't seem to be introduced by the current PR.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/sqllogic-test-2 🔴 failed 4, success 24, total 28 22 min Existing failure
idc-jenkins-ci/integration-cdc-test 🔴 failed 1, success 38, total 39 20 min Existing failure
idc-jenkins-ci-tidb/mybatis-test 🔴 failed 1, success 0, total 1 11 min Existing failure
idc-jenkins-ci-tidb/integration-ddl-test 🔴 failed 1, success 5, total 6 8 min 51 sec Existing failure
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 15 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 14 min Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 6 min 3 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 5 min 54 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 44 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants