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

sysvar: tidb_enable_column_tracking only takes effect when tidb_persist_analyze_options is turned on #53481

Merged
merged 3 commits into from
May 23, 2024

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented May 22, 2024

What problem does this PR solve?

In TiDB we have a global variable called tidb_persist_analyze_options, the default value is true, and it will help us to store the analyze options in the system table mysql.analyze_options.
We know that the Predicate Columns collection feature relies on this system to store the column selection. So if we set tidb_persist_analyze_options to false, the predicate column feature won't work anymore. Every time you need to explicitly ANALYZE TABLE table_name PREDICATE COLUMNS to make sure TiDB only analyses the predicate columns, otherwise auto-analyze it will keep analysing all columns.

So tidb_enable_column_tracking only takes effect when tidb_persist_analyze_options is turned on.

Issue Number: close #53478

Problem Summary:

What changed and how does it work?

I added some checks before we set tidb_enable_column_tracking and tidb_persist_analyze_options. Now, you can only turn on tidb_enable_column_tracking if tidb_persist_analyze_options is turned on.

  1. tidb_persist_analyze_options cannot be turned on when tidb_enable_column_tracking is false.
  2. tidb_persist_analyze_options cannot be turned off when tidb_enable_column_tracking is on.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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.

Fixed an issue where tidb_enable_column_tracking may not work when tidb_persist_analyze_options is turned off
修复了 tidb_persist_analyze_options 关闭时可能导致 tidb_enable_column_tracking 无法工作的问题

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 22, 2024
@Rustin170506 Rustin170506 added the sig/planner SIG: Planner label May 22, 2024
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 22, 2024
@Rustin170506
Copy link
Member Author

Rustin170506 commented May 22, 2024

Tested locally:

  1. Start the tidb cluster: tiup playground v8.0.0 --db.binpath /Users/hi-rustin/vsc/tidb/bin/tidb-server
mysql> select tidb_version();
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                      |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.2.0-alpha-213-gbc145b3afa
Edition: Community
Git Commit Hash: bc145b3afa4c377792f887d08fb6e94e873929df
Git Branch: rustin-patch-tracking
UTC Build Time: 2024-05-22 08:45:27
GoVersion: go1.21.5
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
  1. Set the tidb_enable_column_tracking to on first:
mysql> set global tidb_enable_column_tracking = 1;
Query OK, 0 rows affected (0.02 sec)

mysql> select @@tidb_enable_column_tracking;
+-------------------------------+
| @@tidb_enable_column_tracking |
+-------------------------------+
|                             1 |
+-------------------------------+
1 row in set (0.00 sec)
  1. Try to turn off tidb_persist_analyze_options:
mysql> set global tidb_persist_analyze_options = 0;
ERROR 1105 (HY000): tidb_persist_analyze_options option cannot be set to OFF when tidb_enable_column_tracking is ON, as this will result in the loss of column tracking information
  1. Turn off tidb_enable_column_tracking:
mysql> set global tidb_enable_column_tracking = 0;
Query OK, 0 rows affected (0.01 sec)

mysql> select @@tidb_enable_column_tracking;
+-------------------------------+
| @@tidb_enable_column_tracking |
+-------------------------------+
|                             0 |
+--------------------------
  1. Turn off tidb_persist_analyze_options:
mysql> set global tidb_persist_analyze_options = 0;
Query OK, 0 rows affected (0.01 sec)

mysql> select @@tidb_persist_analyze_options;
+--------------------------------+
| @@tidb_persist_analyze_options |
+--------------------------------+
|                              0 |
+--------------------------------+
1 row in set (0.00 sec)
  1. Try to turn on tidb_enable_column_tracking:
mysql> set global tidb_enable_column_tracking = 1;
ERROR 1105 (HY000): tidb_enable_column_tracking option cannot be set to ON when tidb_persist_analyze_options is set to OFF, as this will prevent the preservation of column tracking information

@Rustin170506 Rustin170506 force-pushed the rustin-patch-tracking branch 3 times, most recently from 4db4e82 to 85f323b Compare May 22, 2024 08:11
@hawkingrei hawkingrei self-requested a review May 22, 2024 08:11
@Rustin170506 Rustin170506 force-pushed the rustin-patch-tracking branch from 85f323b to 2aa6c9f Compare May 22, 2024 08:13
Rustin170506

This comment was marked as off-topic.

@Rustin170506 Rustin170506 force-pushed the rustin-patch-tracking branch from 5fd041c to 60b5017 Compare May 22, 2024 08:20
Rustin170506

This comment was marked as off-topic.

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 74.7481%. Comparing base (6928519) to head (0108b71).
Report is 11 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53481        +/-   ##
================================================
+ Coverage   72.5278%   74.7481%   +2.2203%     
================================================
  Files          1505       1505                
  Lines        429901     430856       +955     
================================================
+ Hits         311798     322057     +10259     
+ Misses        98809      88950      -9859     
- Partials      19294      19849       +555     
Flag Coverage Δ
integration 49.5734% <72.4137%> (?)
unit 71.4579% <89.6551%> (+0.0320%) ⬆️

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

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 50.4742% <ø> (+9.0701%) ⬆️

@Rustin170506 Rustin170506 force-pushed the rustin-patch-tracking branch from 60b5017 to bc145b3 Compare May 22, 2024 08:44
@ti-chi-bot ti-chi-bot 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 May 22, 2024
Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback.)

pkg/sessionctx/variable/sysvar.go Outdated Show resolved Hide resolved
enabled := TiDBOptOn(val)
// If this is a user initiated statement,
// we log that column tracking is disabled.
if s.StmtCtx.StmtType == "Set" && !enabled {
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure why do we need to check the stmt type here. Because we are already in the set func.

@Rustin170506 Rustin170506 requested a review from elsa0520 May 22, 2024 09:02
Copy link
Contributor

@elsa0520 elsa0520 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 bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label May 22, 2024
Signed-off-by: hi-rustin <[email protected]>
@hawkingrei
Copy link
Member

/test all

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 23, 2024
Copy link

ti-chi-bot bot commented May 23, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-22 09:21:05.805735767 +0000 UTC m=+2249819.562871343: ☑️ agreed by elsa0520.
  • 2024-05-23 07:38:32.483466312 +0000 UTC m=+2330066.240601882: ☑️ agreed by hawkingrei.

@easonn7
Copy link

easonn7 commented May 23, 2024

/approve

For the short term, tidb_enable_column_tracking looks good to me, but for the long term, I believe only tidb_persist_analyze_options is reasonable. We don't need so many variables with complex dependencies.

Copy link

ti-chi-bot bot commented May 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: easonn7, elsa0520, hawkingrei

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 the approved label May 23, 2024
@Rustin170506
Copy link
Member Author

/retest

3 similar comments
@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 100aa05 into pingcap:master May 23, 2024
23 checks passed
RidRisR pushed a commit to RidRisR/tidb that referenced this pull request May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The predicate columns feature relies on tidb_persist_analyze_options
4 participants