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

import: check table empty skips using index #39604

Merged
merged 6 commits into from
Dec 5, 2022

Conversation

dsdashun
Copy link
Contributor

@dsdashun dsdashun commented Dec 4, 2022

What problem does this PR solve?

Issue Number: close #39477

Problem Summary:

What is changed and how it works?

  • When pre-checking whether target table is empty, skip using the index and directly scan the record.
  • Added integration tests to verify that.

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 Dec 4, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • lance6716

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 release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 4, 2022
@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 4, 2022

/run-integration-br-test

@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 4, 2022

Integration BR test failed at br_foreign_key. All Lightning tests have passed: https://ci.pingcap.net/blue/organizations/jenkins/br_ghpr_unit_and_integration_test/detail/br_ghpr_unit_and_integration_test/14309/pipeline

@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/run-unit-test

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

please fix unit tests, rest lgtm

// In Lightning, if previous importing is halted half-way, it is possible that
// the data is partially imported, but the index data has not been imported.
// In this situation, if no hint is added, the SQL executor might fetch the record from index,
// which is empty. This will result in missing check.
Copy link
Contributor

Choose a reason for hiding this comment

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

it's still possible that index data in partially imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's still possible that index data in partially imported.

If index data is partially imported, table-empty check will report errors on the second import even if USE INDEX() is not used. So it will be figured out by the current table-empty-check logic.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 5, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 5, 2022
@ti-chi-bot ti-chi-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 Dec 5, 2022
@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 7ebf3c3

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 5, 2022
@D3Hunter
Copy link
Contributor

D3Hunter commented Dec 5, 2022

tried on tiup playground nightly(v6.5.0-alpha-nightly-20221205), cannot reproduce it, steps:

  • run lightning, data imported, but failed before import index
  • rm checkpoint
  • import again:
➜  lightning bin/tidb-lightning --config test-bool-csv.toml
Verbose debug logs will be written to tidb-lightning.log

+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
|  # | CHECK ITEM                                                                                                                         | TYPE        | PASSED |
+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
|  1 | Source csv files size is proper                                                                                                    | performance | true   |
+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
|  2 | the checkpoints are valid                                                                                                          | critical    | true   |
+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
|  3 | table schemas are valid                                                                                                            | critical    | true   |
+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
|  4 | table(s) [`test`.`t`] are not empty                                                                                                | critical    | false  |
+----+------------------------------------------------------------------------------------------------------------------------------------+-------------+--------+
mysql> show create table test.t;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                   |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  `v` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select 1 from test.t  limit 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.01 sec)

@D3Hunter
Copy link
Contributor

D3Hunter commented Dec 5, 2022

/run-integration-br-test

@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 5, 2022
@D3Hunter
Copy link
Contributor

D3Hunter commented Dec 5, 2022

tried on tiup playground nightly(v6.5.0-alpha-nightly-20221205), cannot reproduce it, steps:

  • run lightning, data imported, but failed before import index
  • rm checkpoint
  • import again:
    .....

seems when table rows is small, tidb will use full-table-scan(previous case only has 4 rows)

mysql> explain select 1 from t limit 1;
+-----------------------------+---------+-----------+---------------+--------------------------------+
| id                          | estRows | task      | access object | operator info                  |
+-----------------------------+---------+-----------+---------------+--------------------------------+
| Projection_6                | 1.00    | root      |               | 1->Column#3                    |
| └─Limit_7                   | 1.00    | root      |               | offset:0, count:1              |
|   └─TableReader_11          | 1.00    | root      |               | data:Limit_10                  |
|     └─Limit_10              | 1.00    | cop[tikv] |               | offset:0, count:1              |
|       └─TableFullScan_9     | 1.00    | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-----------------------------+---------+-----------+---------------+--------------------------------+

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Dec 5, 2022
@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 5, 2022
@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

tried on tiup playground nightly(v6.5.0-alpha-nightly-20221205), cannot reproduce it, steps:

  • run lightning, data imported, but failed before import index
  • rm checkpoint
  • import again:
    .....

You can use the data introduced in c0e0c3c , which is reproducible.

@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/run-integration-br-test

@dsdashun
Copy link
Contributor Author

dsdashun commented Dec 5, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 85052b1

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 5, 2022
@ti-chi-bot ti-chi-bot merged commit 35819ee into pingcap:master Dec 5, 2022
@dsdashun dsdashun deleted the fix-39477 branch December 5, 2022 13:40
@sre-bot
Copy link
Contributor

sre-bot commented Dec 5, 2022

TiDB MergeCI notify

🔴 Bad News! [1] 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/integration-cdc-test 🔴 failed 1, success 39, total 40 23 min Existing failure
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 19 min Existing passed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 18 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 40 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 4 min 38 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 4 min 20 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 3 min 49 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 41 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 10 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

@dsdashun
Copy link
Contributor Author

/cherry-pick release-6.1

@ti-chi-bot
Copy link
Member

@dsdashun: new pull request created to branch release-6.1: #40667.

In response to this:

/cherry-pick release-6.1

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 ti-community-infra/tichi repository.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 17, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@dsdashun
Copy link
Contributor Author

/cherry-pick release-6.5

@ti-chi-bot
Copy link
Member

@dsdashun: new pull request created to branch release-6.5: #40669.

In response to this:

/cherry-pick release-6.5

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 ti-community-infra/tichi repository.

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/L Denotes a PR that changes 100-499 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.

Lightning: Table Empty Check Cannot Find Imported Dirty Data on Previous Failed Imports
5 participants