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 extractor for cluster_tidb_index_usage #55416

Merged
merged 4 commits into from
Aug 15, 2024

Conversation

joechenrh
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #50305

What changed and how does it work?

InfoSchemaIndexUsageExtractor is added for cluster_tidb_index usage memtable.

Besides, the explain output of cluster memory table is changed to make it consistent with other memtable.

mysql> explain select * from information_schema.CLUSTER_TIDB_INDEX_USAGE where table_schema = "test";    
+------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+
| id                     | estRows  | task      | access object                  | operator info                                                        |
+------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+
| TableReader_7          | 10.00    | root      |                                | data:Selection_6                                                     |
| └─Selection_6          | 10.00    | cop[tidb] |                                | eq(information_schema.cluster_tidb_index_usage.table_schema, "test") |
|   └─MemTableScan_5     | 10000.00 | cop[tidb] | table:CLUSTER_TIDB_INDEX_USAGE |                                                                      |
+------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+

Before:

mysql> explain select * from information_schema.CLUSTER_TIDB_INDEX_USAGE where table_schema = "test";                                                                                 
+-------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+                            
| id                      | estRows  | task      | access object                  | operator info                                                        |                            
+-------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+                            
| TableReader_7           | 10.00    | root      |                                | data:Selection_6                                                     |                            
| └─Selection_6           | 10.00    | cop[tidb] |                                | eq(information_schema.cluster_tidb_index_usage.table_schema, "test") |                            
|   └─TableFullScan_5     | 10000.00 | cop[tidb] | table:CLUSTER_TIDB_INDEX_USAGE | keep order:false, stats:pseudo                                       |                            
+-------------------------+----------+-----------+--------------------------------+----------------------------------------------------------------------+                            

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.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 14, 2024
Copy link

tiprow bot commented Aug 14, 2024

Hi @joechenrh. 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-sigs/prow repository.

Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.0836%. Comparing base (eeb3d73) to head (5ac9b29).
Report is 10 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55416        +/-   ##
================================================
+ Coverage   74.8640%   75.0836%   +0.2196%     
================================================
  Files          1576       1578         +2     
  Lines        365691     443829     +78138     
================================================
+ Hits         273771     333243     +59472     
- Misses        72108      90462     +18354     
- Partials      19812      20124       +312     
Flag Coverage Δ
integration 49.4430% <66.6666%> (?)
unit 72.1762% <100.0000%> (-1.6542%) ⬇️

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

Components Coverage Δ
dumpling 52.9567% <ø> (-2.2327%) ⬇️
parser ∅ <ø> (∅)
br 52.5529% <ø> (+4.7549%) ⬆️

@joechenrh
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Aug 14, 2024
@@ -3691,7 +3691,7 @@ func (e *memtableRetriever) setDataForClusterIndexUsage(ctx context.Context, sct
dom := domain.GetDomain(sctx)
rows := make([][]types.Datum, 0, 100)
checker := privilege.GetPrivilegeManager(sctx)
extractor, ok := e.extractor.(*plannercore.InfoSchemaBaseExtractor)
extractor, ok := e.extractor.(*plannercore.InfoSchemaIndexUsageExtractor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a method ListSchemasAndTables for InfoSchemaIndexUsageExtractor and avoid using SchemaTableInfos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InfoSchemaIndexUsageExtractor has already implemented schema and table filter, which is used in tidb_index_usage.
The only difference is that for cluster_tidb_index_usage, the request needs to be sent to all tidb instances for execution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I forgot to push some code.

@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 Aug 14, 2024
func (e *memtableRetriever) setDataFromClusterIndexUsage(ctx context.Context, sctx sessionctx.Context, schemas []model.CIStr) error {
err := e.setDataForClusterIndexUsage(ctx, sctx, schemas)
func (e *memtableRetriever) setDataFromClusterIndexUsage(ctx context.Context, sctx sessionctx.Context) error {
err := e.setDataFromIndexUsage(ctx, sctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between clustered_index_usage table and tidb_index_usage table?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, different tidb at the same time may see different schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://docs.pingcap.com/tidb/stable/information-schema-tidb-index-usage#tidb_index_usage

I think each tidb will collect its own index-related statistics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, I ran some query on one node and got this output.

mysql> select * from information_schema.CLUSTER_TIDB_INDEX_USAGE where table_schema = "test" and index_name = "idx_1";
+-----------------+--------------+------------+------------+-------------+--------------+-------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+--------------------------+-----------------------+---------------------+
| INSTANCE        | TABLE_SCHEMA | TABLE_NAME | INDEX_NAME | QUERY_TOTAL | KV_REQ_TOTAL | ROWS_ACCESS_TOTAL | PERCENTAGE_ACCESS_0 | PERCENTAGE_ACCESS_0_1 | PERCENTAGE_ACCESS_1_10 | PERCENTAGE_ACCESS_10_20 | PERCENTAGE_ACCESS_20_50 | PERCENTAGE_ACCESS_50_100 | PERCENTAGE_ACCESS_100 | LAST_ACCESS_TIME    |
+-----------------+--------------+------------+------------+-------------+--------------+-------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+--------------------------+-----------------------+---------------------+
| 127.0.0.1:10081 | test         | t          | idx_1      |           0 |            0 |                 0 |                   0 |                     0 |                      0 |                       0 |                       0 |                        0 |                     0 | NULL                |
| 127.0.0.1:10080 | test         | t          | idx_1      |           1 |            1 |                 3 |                   0 |                     0 |                      0 |                       0 |                       0 |                        1 |                     0 | 2024-08-15 09:46:04 |
+-----------------+--------------+------------+------------+-------------+--------------+-------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+--------------------------+-----------------------+---------------------+

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 15, 2024
@joechenrh joechenrh removed their assignment Aug 15, 2024
@joechenrh
Copy link
Contributor Author

/assign hi-rustin

Copy link

ti-chi-bot bot commented Aug 15, 2024

@joechenrh: GitHub didn't allow me to assign the following users: hi-rustin.

Note that only pingcap members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign hi-rustin

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 15, 2024
Copy link

ti-chi-bot bot commented Aug 15, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-15 00:23:52.339260163 +0000 UTC m=+400317.042729806: ☑️ agreed by tiancaiamao.
  • 2024-08-15 05:54:06.132455204 +0000 UTC m=+420130.835924865: ☑️ agreed by tangenta.

Copy link

ti-chi-bot bot commented Aug 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: GMHDBJD, hawkingrei, tangenta, 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 the approved label Aug 15, 2024
@joechenrh
Copy link
Contributor Author

/test check-dev2

Copy link

tiprow bot commented Aug 15, 2024

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

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test check-dev2

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 881eedd into pingcap:master Aug 15, 2024
23 checks passed
@joechenrh joechenrh deleted the cluster-index-usage branch October 12, 2024 08:51
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. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants