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

*: add statistic lock/unlock function #38387

Merged
merged 1 commit into from
Nov 11, 2022
Merged

Conversation

pingandb
Copy link
Contributor

@pingandb pingandb commented Oct 11, 2022

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:
Sometime peformance drop due to the explain change that caused by statistic info change after data changes in table.
So we want to introduce table statistic lock/unlock function to avoid unexpected peformance drop by statistic changes.

What is changed and how it works?

The main idea is adding new table mysql.stats_table_locked to record which table is locked, and when doing manual/auto table analyze, check whether table is locked, if locked, skip analyse. And I also filter the locked table in session stat collector operations, that session stat collector won't collect the statistic data of locked table.
Add SQL syntax 'lock/unlock stats xxx(table name)' to add/remove table name to/from mysql.stats_table_locked.

  • Add new table mysql.stats_table_locked
  • Add lock/unlock function on statistic handle
  • Filter locked table on manual/auto statistic analyze
  • Filter locked table on session stats collector
  • Add unlock/unlock on SQL parser/Planner/Executor

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.

Support `LOCK STATS` and `UNLOCK STATS` SQL statements.

@pingandb pingandb requested a review from a team as a code owner October 11, 2022 03:17
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 11, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • winoros
  • xuyifangreeneyes

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/invalid-title release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 11, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Oct 11, 2022

CLA assistant check
All committers have signed the CLA.

@pingandb pingandb changed the title Statistic *: add statistic lock/unlock function Oct 11, 2022
@winoros winoros self-requested a review October 11, 2022 07:23
@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 11, 2022
@pingandb pingandb force-pushed the statistic branch 7 times, most recently from 3135d54 to 2678a7b Compare October 13, 2022 08:56
@pingandb
Copy link
Contributor Author

/run-unit-test

2 similar comments
@pingandb
Copy link
Contributor Author

/run-unit-test

@pingandb
Copy link
Contributor Author

/run-unit-test

@pingandb pingandb force-pushed the statistic branch 3 times, most recently from be1e602 to bb32af0 Compare October 14, 2022 05:57
@pingandb
Copy link
Contributor Author

/run-unit-test

@pingandb
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 26, 2022
@pingandb
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 29, 2022
@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 2, 2022
tableID = task.idxIncrementalExec.tableID
}
// skip locked tables
if !statsHandle.IsTableLocked(tableID.TableID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use warnings to remind users that the table is locked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. Add it.

}

if len(tids) > 1 {
err = finishTransaction(ctx, exec, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is better to defer finishTransaction right after begin begin pessimistic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if finishTransaction get failed, 'mysql.stats_table_locked' won't be updated, and "h.tableLocked = tableLocked" won't be execute, so h.tableLocked is consistent with table.
if change to defer finishTransaction , if finishTransaction get failed, table won't be updated but h.tableLocked will be updated, data in table and memory is inconsistent.

@hawkingrei
Copy link
Member

@pingandb Please solve the conflicting.

}

// GetTableLockedAndClear for unit test only
func (h *Handle) GetTableLockedAndClear() []int64 {
Copy link
Member

Choose a reason for hiding this comment

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

Add ForTest to make its scope clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes left a comment

Choose a reason for hiding this comment

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

When locking a partition table, add partition IDs to stats_table_locked. Rest LGTM

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2022

exec := h.mu.ctx.(sqlexec.SQLExecutor)

if len(tids) > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we also have to consider len(pids). Maybe we can all use begin pessimistic for simplicity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnStats)

exec := h.mu.ctx.(sqlexec.SQLExecutor)
if len(tids) > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 11, 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 Nov 11, 2022
@xuyifangreeneyes
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 1d7fdc6

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

sre-bot commented Nov 11, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [3] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test 🟥 failed 1, success 5, total 6 43 min New failing
idc-jenkins-ci-tidb/common-test 🟥 failed 1, success 10, total 11 8 min 48 sec New failing
idc-jenkins-ci-tidb/integration-common-test 🟥 1 min 33 sec New failing
idc-jenkins-ci-tidb/mybatis-test 🔴 failed 1, success 0, total 1 10 min Existing failure
idc-jenkins-ci/integration-cdc-test ✅ all 39 tests passed 22 min Fixed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 23 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 37 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 12 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 50 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 Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ 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.

9 participants